OCX Form Field Collection
Form fields inserted into a document from the Forms toolbar can be accessed
by ActiveDocument.FormFields("formfieldname"). This does not work for fields
inserted into the same document from the Control Toolbox. In a Userform, you
can use the Controls collection but I can't figure out how to access the
fields inserted from the Controls Toolbox. I want to write a construct like:
For each ctl in Controls... Is there a way to do this?
Thanks,
Peter Tag: security - read-only recommended Tag: 89261
Problem with FormattedText
Doing a mailmerge from Excel with Word automation.
I am altering a document and then doing SaveAs.
This runs in a loop and after doing SaveAs I need the original document to
do the same again.
Rather than closing and reopening this document I prefer to keep the text +
formatting in a range
variable and putting that back. Only reason for this is that is quicker.
This is the simplified code I have:
Dim wd As Object
'need to add Word here as there also is a DAO Document!
Dim Doc As Word.Document
Dim rngAllText As Word.Range
Set wd = CreateObject("Word.Application")
Set Doc = wd.Documents.Open(strLetterDoc)
Set rngAllText = Doc.Content.FormattedText.Duplicate
'alter the document here
'do SaveAs here
Doc.Content.FormattedText = rngAllText
At this line line I get error 5937:
Cannot copy content between these 2 ranges.
Thanks for any advice in this.
RBS Tag: security - read-only recommended Tag: 89259
How to write a smart document
How to create a Smart Document
How to use XML in it
How to certify XML file Tag: security - read-only recommended Tag: 89258
*.dot won't run a "Document_Open" Macro when opened from Netwrk Se
I have a *.dot file that is setup on our network server for users to access.
The document opens fine but I need to force open a User Form (UserForm1) as
soon as the template opens. Additionally, if I run the template from my
local machine I can get the User Form to open via the below code.
Private Sub Document_Open()
Application.Run MacroName:="goPCDFiller"
End Sub
(1) What code to I need to execute to get the template to open the User form
when it is deployed on a network server?
(2) Also, is there a code available that forces open WORD to view/run the
template because many of our users have â??Quick View Plusâ?? installed (which is
fine) but it takes over the *.doc and *.dot files when the user tries to open
one of them. Tag: security - read-only recommended Tag: 89257
Word 2007: Binding customXML to Content Control
Hi
I have been trying to get my own XML file working with Content Controls. But
I can not find a way to define the x-path binding to my xml. I will be very
happy if any of you can give me a hint on how to define the mapping (from
within word 2007 - beta 2).
Best Regards,
Kaj Bromose Tag: security - read-only recommended Tag: 89256
Printing Forms from Macros
I have created some protected forms for users but I also have a customized
printing menu. This enables the users to print to different paper trays (we
have several) easily without having to go CTRl P change the paper type and
remember which tray is which each time.
My printing menu lists the paper trays by type.
How can I get the Printing macros to print the protected forms. If I try at
the moment I get Run-time Error 4605.
Any help would be greatly appreciated.
JayM Tag: security - read-only recommended Tag: 89249
Interacting with oracle DB from VBA without Oracle Client on PC?
Hi all,
I noticed that their are some solutions for VB.NET to connect to an Oracle
Database without having an Oracle client on your PC (for eample Core Lab's
OraDirect .Net Dataprovider).
Installing and maintainig Oracle clients is considered to be a pain (various
Database versions require different clients) and is avoided by using more
and more web based applications from Oracle. Only for Word VBA stuff I need
an oracle client to be present on all machines.
I was wondering if anyone has ever tried this from VBA as I would love to
get rid of the Oracle client.
Kind regards,
rVo Tag: security - read-only recommended Tag: 89245
problems with the word-exel comand
Hi, I have a file that first save each one of the words of a document, after
that, it paste the words in an excel file and then counts and deletes the
repeated words, my problem is in the exl.sort command, the program breaks
when it arrives to the sort procedure of excel, I attached the code, please
help
Sub Macro1()
Dim arr1()
cntr1 = 0
a = ActiveDocument.Characters.Count
For n = 1 To a
If ActiveDocument.Characters(n).Text = " " Then
cntr1 = cntr1 + 1
ReDim Preserve arr1(cntr1)
arr1(cntr1) = word1
letter1 = Empty
word1 = Empty
Else
letter1 = ActiveDocument.Characters(n).Text
word1 = word1 + letter1
End If
Next
Set exl = CreateObject("excel.Application")
exl.workbooks.Add
exl.Visible = True
exl.Cells(1, 1).Select
cntr3 = 1
For cntr3 = 1 To UBound(arr1)
exl.Cells(cntr3 + 1, 1) = arr1(cntr3)
Next
exl.Columns("A:A").Select
â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??The program breaks here
exl.Selection.Sort Key1:=Range("A2"), Order1:=xlDescending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??â??The program breaks here
For b = 2 To UBound(arr1)
cntr12 = 1
For C = 2 To UBound(arr1)
If exl.activesheet.Cells(b, 1) = exl.activesheet.Cells(C, 1) And b <> C Then
exl.Rows(C).Delete
C = C - 1
cntr12 = cntr12 + 1
If exl.Cells(C, 1) = Empty Then
GoTo endsub
End If
End If
Next
exl.Cells(b, 2) = cntr12
Next
exl.Range("A1") = "Word"
exl.Range("B1") = "Counter"
exl.Columns("A:A").Sort Key1:=Range("A2"), Order1:=xlAscending,
Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
endsub:
End Sub
thanks Tag: security - read-only recommended Tag: 89244
reformating a string...
Hello,
I have a word document that looks as follows:
{"word1 / word1a"},
{"word2 / word2a"},
{"word3 / word3a"},
.....
{"word1000 / word1000a"}
What I need to do is remove the '/ wordxa' from the document so it
looks like this:
{"word1"},
{"word2"},
{"word3"},
.....
{"word1000"}
Any help would be appreciated.
Thanks,
RABMissouri2006 Tag: security - read-only recommended Tag: 89239
Adding watermark to every page
Hi all,
I have a bit of a panic on the go here and would like to ask for assistance.
Can anyone suggest how I could programmatically (using VBA) add a watermark
to every page in every section in a 10 to 20 page word doc?
I want to add the word "COPY". I thought maybe I could add a specific sized
textbox with hidden borders, containing COPY in large pale grey font colour
(maybe running vertically in the textbox). Then set the textbox to appear
behind the normal text. How on earth I would go about that, I dont have the
faintest idea.
Anyone prepared to offer help or suggest an alternative method?
Unfortunately I dont have enough time to try and fubble around for days on
end like I isually do.
Any help or suggested code would be greatly appreciated.
Many thanks
Gem_man Tag: security - read-only recommended Tag: 89236
VBA Reading a Word Document's Form Field into a User Form Text Box
How do I grab the value from an Form Field in an active document and then
place that value into a User Form that has a corresponding text box. I
thought it would be something like this but I canâ??t seem to get it to work.
Private Sub UserForm1_Initialize()
Me.tbLastFirstMiddle.Value = ActiveDocument.FormFields("docLastFirstMiddle")
End Sub Tag: security - read-only recommended Tag: 89232
Header/Footer not protected in form
Hello,
I have a document template protected for forms. When the user creates a new
document based on the template, they can click on the header. This switches
them from page layout view to normal view and creates a header pane at the
bottom of the document to allow the user to edit the header. This is not what
I want. I don't want the users to be able to touch the header in any way. The
reason I need a header is that the form fields are in table rows and can
expand, causing the document to end up with more pages than the template it
was based on.
Any help would be appreciated.
Thanks! Tag: security - read-only recommended Tag: 89225
printing to multiple printers with macro?
Is there a macro that I could write that could print a MS word file to
one printer, and then also print it to another printer . Both printers
are remote / network printers Tag: security - read-only recommended Tag: 89216
Hiding text based on custom document property
Good afternoon, all,
I am trying to show/hide text based on a custom document property,
Audience. When my document opens, a form appears with three options,
All, Agency, and Program Office.
Here is the code behind the form button's onClick event:
Private Sub cmdOpen_Click()
Dim st As style
If Me.Controls("optAll").Value Then
ActiveDocument.CustomDocumentProperties("Audience").Value = "All"
ElseIf Me.Controls("optAgency").Value Then
ActiveDocument.CustomDocumentProperties("Audience").Value =
"Agency"
Else
ActiveDocument.CustomDocumentProperties("Audience").Value =
"ProgramOffice"
End If
If Me.Controls("optAll").Value Then
For Each st In ActiveDocument.Styles
If InStr(st.NameLocal, "Agency") > 0 Then
st.Font.Color = wdColorBrightGreen
st.Font.Hidden = False
ElseIf InStr(st.NameLocal, "ProgramOffice") > 0 Then
st.Font.Color = wdColorRed
st.Font.Hidden = False
End If
Next
Else
For Each st In ActiveDocument.Styles
st.Font.Color = wdColorAutomatic
If InStr(st.NameLocal, "Agency") > 0 Then
st.Font.Hidden = Not Me.Controls("optAgency").Value
ElseIf InStr(st.NameLocal, "ProgramOffice") > 0 Then
st.Font.Hidden = Not Me.Controls("optProgramOffice").Value
End If
Next st
End If
ActiveWindow.View.ShowHiddenText = False
frmAudience.hide
End Sub
So...first I set the custom document property.
If the user chooses the option labelled All (which I would do when I am
creating this manual) I want to show all styles, with any style
containing the word 'Agency' in its name showing as bright green text
and any style with ProgramOffice showing as red.
If the user choosed the option labelled "Agency" I want only the styles
containing 'Agency' to show, and have all styles containing
'ProgramOffice' to be hidden. So, I set the Hidden property of all the
styles containing Agency to the opposite of the option control. In
other words, if Agency was selected, then
Me.Controls("optAgency").Value will be true, and I want the font for
the styles containing 'Agency' to have a hidden property of false.
The problem is that after running the lines that assign the value to
st.Font.hidden, st.Font.hidden equals -1. I found one posting that I
didn't really understand, but it seemed to say that this was because
the style was a paragraph style.
So, can I do what I want? If so, what am I missing?
Any ideas, resources, references would be greatly appreciated.
Thanks,
Kathryn Tag: security - read-only recommended Tag: 89212
VBA into already created table(s) in a Header or Footer
MS Word - VBA into Header or Footer (and into a table in the same)
Is there a way to allow gain access to a header or footer in Word via VBA?
I have a one page form full of tables (Page 1) and the narrative begins on
Page 2. There is a header and footer on page 2 and subsequent pages (but not
on page 1). The header and footer have tables and I need to be able to
bookmark the tables somehow and copy certain data from page 1 to this header
and footer.
As I see it, there are two ways to do it:
#1 Use a VBA â??prompt boxâ?? (UserForm) for the data to be captured and force
the data into the header for footer as well as certain fields on Page 1.
OR
#2 Have a macro run on a Text Form Field "EXIT" which automatically COPIES
and PASTES data from Page 1 to the header & footer on Page 2
I have tried where â??tblLastFirstMiddleâ?? is the Form Text Field / Bookmark
and vLastFirstMiddle is the text box control on VBA UserForm.
ActiveDocument.FormFields("tblLastFirstMiddle").Result =
vLastFirstMiddle.Value
This works fine for Page 1 but I have yet to be able to (1) manually place a
bookmark / text form field in an already created header or footer and (2)
call that bookmark in the header or footer and (3) Copy and Paste the data
into it.
Any suggestions? Tag: security - read-only recommended Tag: 89210
Form Field Entry & Exit Macro drop-down list
Does anyone know where the list of macros is taken from for the entry and
exit macro for form fields? I am building a form and have added a textbox. I
want to execute a macro on exit. When I click on the drop-down list
associated with the exit macro on the Text Form Field Options dialog box, the
only macros I see are ones in my Normal.dot file. I want to select a macro I
have written in the form which has been saved as a .dot file.
Thanks!
Peter Tag: security - read-only recommended Tag: 89193
HOWTO Keep original document name after a forced SaveAs.
HOWTO Keep original document name after a forced SaveAs.
Please help,
I have script to force the current document to be saved using the
ThisDocument.SaveAs method. After I invoke the SaveAs, the "Name" of the
document changes from whatever it was to the path name I give in the "SaveAs"
call. I want the name to go back to the original name, but the
ThisDocument.Name property is read only, and won't let me change it back.
How can one do this? Is there a way to change the name back? Is there
perhaps a way the "ThisDocument" can be copied to a dummy document, then the
dummy saved via SaveAs and then destroyed without any GUI? Tag: security - read-only recommended Tag: 89192
RegEx Range.Text object corrupting embedded footnotes
I have a macro which processes text using Regular Expressions (to find run-in
heads in paragraphs). It seems that regular expressions will only work on the
Range.Text object and not Range.FormattedText. I thought I had most of the
kinks worked out of this but found a new wrinkle yesterday. It seems that, if
the text of a paragraph is altered by a RegEx, then the embedded footnotes in
that paragraph are broken. I have a sense that this is because the proper
information isn't be passed back to the document by the Range.Text object
when a replacement is made (duh). Before I sit down and write a macro that
cuts out the embedded footnotes and replaces them with a marker before the
RegEx is run and then reverses the replacement after the RegEx is run, I
thought I would check with the experts and see if there are any better (and
easier) approaches out there.
I have tried replacing the RegEx searches with S/R using Word's wildcard
search options but can't achieve the desired search complexity with them. I
always run into the "expression is to complex" error. As a side question, are
the limitations of Word's Wildcard Search listed anywhere. The one major one
I've encountered is the limitation to 7 groups instead of the regular 9.
There seem to be others but I can't recall them right now.
Anyway, any suggestions would be appreciated.
Thanks,
Jeff Tag: security - read-only recommended Tag: 89190
cehck for page numbers in footer word doc
hi
i need to check with visual basic macro if a page number is define in a
word file.
i need to know if any kind of page number is exist by the code and how
to remove it
thanks Tag: security - read-only recommended Tag: 89187
custom dictionaries seem to get corrupted
Dear all,
My custom dictionaries (for spelling checks) often don't accept newly added terms, or I have to klick 'Add' twice before a new entry is added, and then, Word stops again at newly added term as if they weren't already in the dic file.
Now when I open the dic file, some entries seem to be displayed vertically (ech letter is a new entry). Other entries are in the file twice (AV-button). Can anyone explain/solve this behavior?
Shirley Nomey
Word XP 2002 on Windows XP SP2.
AMD
AV-button
C
o
n
f
i
g
F
r
e
e
H
T
M
L
-
c
o
d
e
H
T
M
L
-
AV-button
AV-features
AV-solution
AV-PC
BDJ
Blu
Blue-ray
Bluetooth
Centrino Tag: security - read-only recommended Tag: 89185
How do I code VBA to hit button on a different worksheet?
I have a protected worksheet that has a button that I want to execute
using VBA.
The worksheet in question is protected with the exception of certain
cells where I can paste values.
I am creating a VBA to do all the pasting but I can't figure out how to
execute the button.
Run or Call don't work.
Help.
TIA. Tag: security - read-only recommended Tag: 89181
Word 2003 page numbers
Is it possible to read the page number of a word document at the cursor
location from VBA? Tag: security - read-only recommended Tag: 89176
Saving documents from templates with form field information
I have a template with multiple text and number form fields, including
'project number', 'project manager', and 'site name'. I want to set up a
standard naming convention for the documents from this template with a
combination of the form fields. I then want to set up a macro to save the
document with that name.
For example: I want to save and name the document "project number-project
manager-site name.doc", where each of those variables are the actual data
that the user has filled in the form.
I have bookmark-named all of the fields on the template. I have also
selected the "calculate on exit" checkbox on all of the fields. I see how to
set up a calculated field on the form, but it won't work with text fields. I
also see how to set up a cross-reference, but that's only to one bookmark at
a time.
Any ideas? Thanks, Ruth Tag: security - read-only recommended Tag: 89171
Find Blank lines between paragraph
I am very new in vb. I need to find blank lines between paragraphs and
get the particular paragraph.
For example:
alksdjf alkdjf alkdjf alskdjf aldfj a;dfljkaldfj.da flkd;sa
jflkdsa jf;ldkj f;lakjd fkasdj f;ajd fadsf
df aldfjakldf.
sdlfkj aslkdf jalksd fjlakdj faldsk fald [SDF SDFK SDF]. adklf
ajdkl;fj alksdjf alskdjf .adj.fka jdfk.adf.adfa.
So, basically i want to get second paragraph since the tag([SDF SDFK
SDF]) is in second one so with the index of "[", I am trying to get
text after the blank line and before the blank line at the end of the
paragraph..
Any idea
if somebody can help that would be great. thanks Tag: security - read-only recommended Tag: 89170
AutoText Global Template
Hi
Is there a way that a group of workers can all share the same autotext
entries and, importantly, all add entries for the others to use? To be
successful, the facility would need to allow any of them to add their own
entries for the benefit of the others in the group, just as simply as if they
were adding an entry to their own Normal.dot.
Thanks
Dave Tag: security - read-only recommended Tag: 89166
FAQ - Frequently Asked Questions - vba - please read before posting - unofficial August Posting
FAQ = Frequently Asked Questions - brief - vba - unofficial
This FAQ is posted every ten days or so.
Please save us all some time by reading it before posting to the
news group.
This newsgroup is about VBA - Visual Basic for Applications -
which is the programming language for Word 97-2003 (macros).
There is a longer FAQ with more questions and links that is
regularly posted in the non-VBA Word newsgroups. You may want
to check that out as well.
--- BEFORE POSTING ANYTHING PLEASE READ THESE ---
http://www.mvps.org/word/FindHelp/Posting.htm
http://www.dts-l.org/goodpost.htm
http://users.tpg.com.au/bzyhjr/liszt.html
Reading these articles will help you get a quick and meaningful
response to your question rather than just more questions for you.
It may keep your message from being screened or bounced.
A few basics, though:
(1) Be nice; everyone answering questions here is a volunteer.
(2) Post a question in only one newsgroup generally. If you
_have to_ post in more than one, post a _single_ message and
put both newsgroups in the header for that _single_ message.
(3) Do not attach anything to a message.
(4) The only really stupid question is the one you don't ask.
(5) Do not use your real email address unless you want spam.
(See bottom for sample.)
The reasons for the requests are spelled out on the web page.
A longer version of this FAQ is also on the Internet at
http://addbalance.com/word/index.htm
Newsgroup Archives:
http://groups.google.com/advanced_group_search
MVPs FAQ site:
http://word.mvps.org/FAQs/MacrosVBA.htm and
http://word.mvps.org/FAQs/Userforms.htm
To the extent there is any "official" FAQ, this is it.
---
Also, before posting, you may want to look at the following
questions to see if yours is among them.
---------- ---------- ---------- ---------- ---------- ----------
1. I see a macro in a newsgroup I would like to try. How
do I add it to my template?
http://addbalance.com/word/macrosfromnewsgroup.htm or
http://www.mvps.org/word/FAQs/MacrosVBA/CreateAMacro.htm
http://www.gmayor.com/installing_macro.htm
2. What are some good books for me to read about Word?
http://addbalance.com/word/wordbooks.htm and
http://www.mvps.org/word/Tutorials/BookRecommendations.htm
3. How can I run a macro automatically when a document opens,
closes, is created?
http://www.mvps.org/word/FAQs/MacrosVBA/DocumentEvents.htm
4. How can I distribute or backup macros / customizations?
http://word.mvps.org/FAQs/MacrosVBA/DistributeMacros.htm
http://addbalance.com/word/movetotemplate.htm
5. What is an MVP?
http://www.mvps.org/word/AboutMVPs/index.html and
http://addbalance.com/word/mvp.htm
6. I need to make a form to...
Userforms are custom dialog boxes written using vba.
If you want a fill-in-the-blanks form you want what Word
calls an online form. Look in Word's help for that,
and for more info on online forms follow the links at:
http://addbalance.com/word/wordwebresources.htm#Forms
especially Dian Chapman's series of articles
If you want a custom dialog box that you code with VBA commands
you want a UserForm. Take a look at:
http://www.mvps.org/word/FAQs/Userforms.htm
7. Where can I find more information on the Web?
http://addbalance.com/word/wordwebresources.htm#webvba
http://www.mvps.org/word/FAQs/MacrosVBA.htm
http://www.mvps.org/word/FAQs/Userforms.htm
http://www.mvps.org/word/FAQs/Customization.htm
http://www.mvps.org/word/FAQs/OfficeInterdev.htm
8. Recorded macros...
http://word.mvps.org/FAQs/MacrosVBA/UsingRecorder.htm
How do I edit or change?
http://word.mvps.org/FAQs/MacrosVBA/ModifyRecordedMacro.htm
Recorded macros are usually inefficient and sometimes just
plain don't work. Nevertheless, they often do work and can
be a good place to start!
9. How can I enter something once in a document and have it repeat
elsewhere? (Not really vba, but it keeps being asked.)
http://gregmaxey.mvps.org/Repeating_Data.htm
10. I can't save my customizations - AutoText, menus, etc.
Can't save normal.dot...
If you have Adobe Acrobat 7 installed see the last section of
http://www.gmayor.com/lose_that_adobe_acrobat_toolbar.htm.
Otherwise, hold down the Shift key when selecting the File
menu and select Save All.
See also http://www.adobe.com/support/techdocs/331259.html.
11. How can I get a template to show up under a tab with
File => New?
What are templates? Global templates? Document templates?
http://addbalance.com/usersguide/templates.htm
Comments / corrections / additions may be sent to
wordfaq@no.spam.addbalance.com. Remove no.spam from the
address.
Posted 7 August 2006
Charles Kenyon (the editor) Tag: security - read-only recommended Tag: 89165
Modifing Word's HTML
I'd like to modify the HTML Word generates. How is this done through VBA?
An example of a change might be:
From: <table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0
style='border-collapse:collapse'>
To: <table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0
style='behavior:url(MyHighlight.htc);border-collapse:collapse;'
slcolor=#ffffcc hlcolor=#BEC5DE> Tag: security - read-only recommended Tag: 89162
Putting a custom toolbar just after the standard toolbar
In a global add-in (.dot) file I have some code that adds
a toolbar. I would like this toolbar to show on the same row as the standard
toolbar
and just behind it. So, it may have to squeeze between the standard toolbar
and the formatting toolbar.
Have tried several constructions, but I just can't manage to achieve this.
It always ends up on it's own row, above or below the row with the standard
toolbar.
Is there any way to do this?
This is my code, leaving out the code that deals with the button on this
toolbar:
Sub MakeToolBar()
Dim cBar As CommandBar
Dim bVisible As Boolean
Dim cmdBarButton As CommandBarButton
'remove the old Menu Bar buttons
'-------------------------------
On Error Resume Next
Application.CommandBars("Menu Bar").Controls("Patient Data Entry").Delete
Application.CommandBars("Menu Bar").Controls("&PDE").Delete
CustomizationContext = ThisDocument
If ToolbarPresent("WordEntries", bVisible) = False Then
Set cBar = CommandBars.Add("WordEntries", msoBarTop, False, True)
Else
Set cBar = CommandBars("WordEntries")
End If
With cBar
.Visible = True
.RowIndex = 1 'same level as standard toolbar
End With
End Sub
Function ToolbarPresent(strToolbarName As String, bVisible As Boolean) As
Boolean
Dim cBar As CommandBar
For Each cBar In CommandBars
If cBar.Name = strToolbarName Then
If cBar.Visible Then
bVisible = True
End If
ToolbarPresent = True
Exit Function
End If
Next
End Function
RBS Tag: security - read-only recommended Tag: 89158
problem in handling more than one button in a COM Addin for Word
I have developed a COM addin in visual C++ for Office Word which creates a
toolbar whit two buttons on it, but I don't know how to handle more than one
button events. The problem is that my addin runs the same code for the click
of any of the two buttons.
The DISPID dispidMember (first input) of my class's Invoke function is 1
independent of which button has been clicked. Tag: security - read-only recommended Tag: 89153
problem in handling more than one button in a COM Addin for Word
I have developed a COM addin in visual C++ for Office Word which creates a
toolbar whit two buttons on it, but I don't know how to handle more than one
button events. The problem is that my addin runs the same code for the click
of any of the two buttons.
The DISPID dispidMember (first input) of my class's Invoke function is 1
independent of which button has been clicked. Tag: security - read-only recommended Tag: 89152
Bug with cross-references in VBA?
Hallo,
I'd like to insert a cross-reference (reference to: only label and
number) to a self defined caption (Insert->reference->caption) using a
macro. Normally this wouldn't be a problem:
Selection.InsertCaption Label:="Test", TitleAutoText:="InsertCaption1",
_
Title:="", Position:=wdCaptionPositionBelow, ExcludeLabel:=0
Selection.InsertCrossReference ReferenceType:="Test", ReferenceKind:= _
wdOnlyLabelAndNumber, ReferenceItem:="1", InsertAsHyperlink:=True, _
IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" "
But I need a caption with the option "Exclude label from caption".
Now - if I'm using this type of caption (ExcludeLabel:=1) and insert
a cross reference manually, everything is still fine, but if I'm
executing the same command as a macro Word 2003 is inserting nothing
(don't know about other Word versions) ! I even recorded the successful
manual insertion with the recorder (which is creating the same code
lines as above). When I'm executing the macro nothing is inserted.
Does anybody have any idea?
thanks
Dom Tag: security - read-only recommended Tag: 89146
How do I insert 1 of 35 possible paragraphs into 1 form field?
I am trying to create a field where I can pull a dropdown box and choose
anywhere from 35 possible entries. When I select the item I need, it will
fill the field with 1 paragraph of predefined text for that field, so 35
possible paragraphs of text can be selected. In summary I am a probation
officer and I want to automate my violations I write, so I can choose
"Positive Drug Test" or "Moving w/o Notifying" and then it will fill the
field with the corresponding legal verbage. Is this possible? Tag: security - read-only recommended Tag: 89139
Autosize excel sheet to fit correctly with in word
I have a quote spread sheet that is some times 5 rows, some tims 20
rows or some where in between.
Is there a way of making Word display only the required amound of the
sheet to cover from Row 1 to the last row that has my totals column?
Timmy D Tag: security - read-only recommended Tag: 89137
Why it is impossible?
It is strange, why nobody except Ed was not involved in the problem of
FileSearch object in Word 2003 macro. Look on the piece of a macro and
imagine that you want to find all the files in the directory "x" which
contain at least two keyword, keyword 1 AND keyword 2. I could not to create
string "z1" which would do this job, in spite it is possible in the Word
2003 itself (Look File -> FileSearch -> Advanced).
With Application.FileSearch
.NewSearch
.FileType = y
.SearchSubFolders = True
.FileName = ""
.MatchTextExactly = True
.TextOrProperty = z1
.LookIn = x
.Execute
TotalFiles = .FoundFiles.Count
If TotalFiles = 0 Then
MsgBox ("There are no files in the folder!" & _
"Please type another folder to list.")
GoTo Folder
End If
For i = 1 To TotalFiles
MN1(i) = .FoundFiles(i)
Next i
End With
I did it with "brute force", creating the arrays of filenames with
different keywords (like MN1 in the code) and then taking only members of
arrays which present in every array, modelling in this way logical "AND".
But I suspect that more elegant solution may be found. That is your opnion? Tag: security - read-only recommended Tag: 89129
How to format whole paragraph if it contains a keyword?
Hi All,
I've been trying to figure out there is a way to select an entire paragraphs
based on a keyword within the paragraphs (e.g., I'd like to change the
entire paragraphs containing the keyword "^pCHAPTER" [paragraph mark +
uppercase-word chapter].
Is there a way to do this via Find&Replace or another way.
Thanks so much, rgds, JS Tag: security - read-only recommended Tag: 89124
Setting Page Width, Height, and Orientation
I created an Access report and saved it as a word document. I then set the
Page Width, Page Height and Orientation. When I checked the document under
page set up all of the set parameters were there but they don't seem to take
effect until I click OK. Is there some command that can simulate OK in the
commands listed below ?
Set docSource = wdApp.Documents.Open(strReportRtf)
With wdApp.ActiveDocument.PageSetup
.PageWidth = InchesToPoints(dRptWidth)
.PageHeight = InchesToPoints(dRptHeight)
If strRptOrient = "P" Then
.Orientation = wdOrientPortrait
Else
.Orientation = wdOrientLandscape
End If
End With
docSource.SaveAs FileName:=strReportDoc, FileFormat:=wdFormatDocument
docSource.Close Tag: security - read-only recommended Tag: 89110
pages not in footer
Is it possible to write inside the text "This the page number ..." & put the
number of current page?
When i do it with the reference fields, it ask me always to update it... Tag: security - read-only recommended Tag: 89099
excel copy cells to word template
I have a large workbook and I want to copy cells from one sheet called
Menu to a specific word template called PDC_MCC_IR.dot and save the
word template as a word document. I have a bit of code that can open a
word document and past information from cells in the word document but
I need help for the rest. Can anyone help me. Here is the code that I
already have.
Sub Excel_to_Word()
Dim appWord As Word.Application
Set appWord = New Word.Application
appWord.Visible = True
Range("b4:c10").Copy
appWord.Documents.Add.Content.Paste
Application.CutCopyMode = False
End Sub
Thanks Garry gtpighin@shaw.ca Tag: security - read-only recommended Tag: 89094
Error: AppName: winword.exe AppVer: 11.0.8026.0
Can anyone help with Error message? Is it Access Tools Reference related to
those few users?
Details: Using Word and Access 2003; the template is housed on a network
but is not directly accessed by users. They run a macro I created that
opens a document based on it. The template has been revised a few times,
and the code in the template has been tweaked. Would that have anything
to do with it? What other details should I give?
I've got a problem with a few users (out of 55) whose Word sessions
crash *every* time they open a document based on a certain automated
template I created. I've Googled the following error report generated by
Word when it crashes, but am not finding any solutions specific to this
problem, enough to safely correct it:
Error signature
AppName: winword.exe AppVer: 11.0.8026.0 AppStamp: 4468c5b1
ModName: vbe6.dll ModVer: 6.4.99.72 ModStamp: 40b29ba6
fDebug: 0 Offset: 001c3fac
The template has two sections that are protected. The protected sections
have text fields that are bookmarked, and one macrobutton that allows
the user to add extra lines. There are a few macros built into the
template that run when the user enters and exits certain fields. There
is also code built into the template that allows the user to click a
button and send the information to a database into Access. For 90% of
the users, there are no problems working with the documents based on
this template. However, I've got a few users whose Word sessions crash
every time they open a document based on this template. I have tried
renaming their Normal templates and updating Office 2003 with the latest
patches. The problem is I don't know where to begin to diagnose the
problem. Why can most users open the documents based on the template but
those few can't? Can someone please tell me where I should begin
looking? I've tried recreating the problem on my computer, but I can
open the documents just fine - no crashing. I don't know if I should be
looking at a setting, if I should attempt to recreate the template,
remove the code from it, check out libraries, or what. Maybe if I
understood a little better what happens when you open a document that is
based on a template that has fields and macros, I'd understand where to
begin diagnosing the problem.
Desperately, Tag: security - read-only recommended Tag: 89086
Parsing lines of text
I have a Word document that contains hundreds of similarly-formatted
reports (about 30-40 lines of text with carriage returns), with lines
that flag the start of each report and lines that are specifically
flagged that I need to copy and paste at the bottom of the document.
What I need to do is activate a macro that looks for the first start
flag ("START REPORT"), copies the line of text underneath it, then
looks for rows flagged as "LAUNCH DATE" and "DETAILS", copies those,
and then dumps all four rows of text at the bottom of the document.
Then, finds the next report (within the document) and repeats the
process until it hits the end of the document.
Any thoughts would be greatly appreciated. Thanks! Tag: security - read-only recommended Tag: 89085
How to set up macro that copies text to another place in same docu
I'm trying to set up a form in Word 2002. I want to set up the form such
that when a user enters a number in one place in the document, the same
number is automatically entered in a second location. I've tried running a
macro on exit from the first text form field that copies then pastes the
number to the other form field below, but I get an error message (Microsoft
Visual Basic. Run-time error 4605: This method or property is not available
because the obfect refers to a protected area of the document). I tried it
again, by taking out the second form field, and just trying to paste the
number to a specific spot, but I get the same error message.
What am I doing wrong?? Tag: security - read-only recommended Tag: 89078
Requesting VBA Code to Copy from Word as Bmp
Hi. I have a Word doc which consists of of some paragraphs of text,
tables, and a few inserted pictures. The contents of this Word doc
are constantly changing. My aim is to copy all of its contents as a
single bmp file, and then paste this bmp file into an Excel xls file.
The steps I've used to try to do this manually are:
(1) Ctrl & A (select all)
(2) Ctrl & C (copy)
(3) place my cursor at the desired location on the Excel file and
use Edit > Paste Special - Picture (Enhanced Metafile).
The resulting paste into Excel does include all the text and table info
but not any of the pictures. I am hoping for the means to get a
"complete" copy and paste (that includes any inserted pictures from
the Word doc), and the proper Word VBA code to do this.
I know the Word VBA for steps 1 and 2 are:
Selection.WholeStory
Selection.Copy
Since the second line of code above does not perform a
"complete" copy, I'm sure that line will have to be changed.
Could you please tell me what the proper code would be to
achieve this? I would be most appreciative for your help.
(By the way. To me it is "odd" that this can be easily done from
Excel into Word. In Excel, if you paint in an area while holding
down the Shift key, you will be able to copy any of its contents
(including bitmaps) and then paste this as a single bitmap
into Word. I say "odd", because I would have thought this to be
a simple matter going from Word into Excel.)
I look forward to your answers and you have my sincere thanks.
God bless you.
Ken Wilson Tag: security - read-only recommended Tag: 89069
Apply a Template to all documents in folder and subfolders
Hi:
I have created a template that I would like to apply to all documents in a
specific folder and its subfolders. Is there any way to do so
programatically? Any help would be appreciated.
Thanks,
Dave Tag: security - read-only recommended Tag: 89063
Writing a macro for word in c#
Hi,
i want to write a macro in .NET and add that macro to the word
programmatically. how do i do this.
any help will be great help.
--
ravib Tag: security - read-only recommended Tag: 89057
add 28 days from present date
I need to add 28 days from todays date to a field.
ex: Todays date is 8/4/2006, in the next box (or field) I need to show 28
days from now which equals 9/1/2006. Tag: security - read-only recommended Tag: 89056
Autonew macro doesn't fire on new document
I have a quite annoying problem with the autonew macro. I am using Word
2003.
In a template, i made the autonew macro, i tested it, and it does exactly
what it is supposed to do, as long as i am working directly in the .dot
file.
When i doubleclick the .dot file Word opens with a new document filled with
everything from the template, even the macro, but it's not firing up, and
when i go to Extra --> Macro --> Macro's... it is not showing the macro
anymore. If i then open Visual basic, all the code is there. Then if i add a
bit of extra code (another sub that just puts up a MsgBox with some crap)
suddenly all the macro's are usable again.
This kinda nullifies the use of the autonew macro as i still have to
manually add code and start it up. Does anyone have any clue why my macro
code is copied to the new document, but is not available for use until i
edit the code?
Regards,
M. Vlaardingerbroek Tag: security - read-only recommended Tag: 89053
Auto macros
I am trying to do Auto Macros in a different template than the
normal.dot. I create a module called AutoClose or AutoExec or AutoNew
and within those modules I have a sub Main(). None of these macros will
run unless I place them in the normal.dot. I can't have them in the
normal.dot as I cannot replace the clients normal.dot. I created a
different add in called adn.dot and place them in there as a module but
it won't run unless I move them back to normal.dot. Any suggestions? Tag: security - read-only recommended Tag: 89044
Error handling in VBA code
Hi,
I've developed the following function to test if some style does exist in a
document:
Function xstyle(aStyle As String) As Boolean
Dim sty As style
On Error GoTo notexist
Set sty = ActiveDocument.Styles(aStyle)
Set sty = Nothing
xstyle = True
Exit Function
notexist:
xstyle = False
End Function
For some time this has worked, but now when the style does not exist the
statement "Set sty = ActiveDocument.Styles(aStyle)" generates an error "the
asked member of the collection does not exist" and stops execution in stead
of jumping to the label Notexist:.
What can be at hand? Why the error handling doesn't work?
Thanks for suggestions
Henk Tag: security - read-only recommended Tag: 89041
Hello,
Through VB and the Word object model is it possible to un-select the tools >
options > security > Read-only recommended check box?
"greg" <greg@greg.com> wrote in message
news:OQK4rM$uGHA.3500@TK2MSFTNGP06.phx.gbl...
> Hello,
> Through VB and the Word object model is it possible to un-select the tools
> > options > security > Read-only recommended check box?
>
> thanks
>
>