FAQ - Frequently Asked Questions - vba - please read before posting - unofficial February posting
FAQ = Frequently Asked Questions - brief - vba - unofficial
This FAQ is posted weekly.- more or less
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
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://www.mvps.org/word/ 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
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
Comments / corrections / additions may be sent to
wordfaq@no.spam.addbalance.com. Remove no.spam from the
address. (This is a "proofed" email address, I hope.)
Posted 1 February 2005
Charles Kenyon (the editor) Tag: Preview of Document Tag: 62590
date in English
I'm programming two userforms, one for use in Dutch, one for use in English.
I use an input box which defaults to the creation date (
Me.Controls("Textbox8").Text = Format(Date, "Mmmm dd, yyyy"))
However, since my application language is Dutch, the result shows the Dutch
results on the Dutch as well as on the English form.
How can I change this? Tag: Preview of Document Tag: 62588
VBA textboxes
Hi
I am working on a Word 2003 application in which I populate the document
with data that I retrieve from a database. The number of pages within the
document depends on the amount of records returned from querying the
database. I have set up an auto text entry that contains all of the fields
(textboxes) for each record. On startup I insert the autotext entries so that
the document displays the correct number of pages to display detail for all
the selected records.
I now need to populate textboxes on the various pages in the doc. I know the
names each textbox (e.g. txtAddress, txtAddress1 for the next page, etc.) but
I don't know how I can set the .text property of each textbox in code because
only the textboxes on the first page will be available at design time.
Can anyone suggest a way around this? Will I nee to try a different appraoch?
Thanks
Darach Tag: Preview of Document Tag: 62586
Showing the Document Map
Hi,
With the help of a Global Template (Main.dot), I start the creation of
a document (based on Report.dot).
After the document is finished i want the readers automatically have
the "Document Map" visible.
The document is distributed in a large organisation, and at home of the
readers (students). My problem rises when the connection to the
Report.dot is broken.
How do i add to the document:
ActiveDocument.ActiveWindow.DocumentMap = True
Or is there a better solution?
Thank you for your time.
Ward Tag: Preview of Document Tag: 62584
Search and Replace in String
Can anyone tell me if it is possible to perform a search and replace inside
of a string?
I have a string called myData that contains an emdash that I need to change
into a hyphen and I cannot find a way to do this.
Any assistance would be greatly appreciated.
Thank you for taking them time to read this. Tag: Preview of Document Tag: 62574
Find & Replace not working!!
I need pretty bad help:
The usual Find and Replace under the Microsoft Visual Basic Editor does not
work at all!! Nothing fancy, I just click on Edit - Find and type some
character, push enter and nothing happens. It works fine with all other
applications including Word. It simply does not work with the VB editor in
Word. Here's what I have tried:
a) Removed Normal.dot (just so it is related in some weird way)
b) Uninstalled Office and installed it again
c) Restarting the comp / scandisk (again, whatever that'll remotely make it
work)
It's very annoying to go through a million modules without the Find thing
working!! Has anybody ever experienced this? Please, please do not suggest
reinstalling Windows!! It's a big inconvenience and I don't have any ghost
image of the hard drive!
Thanks for your time / responses.
Vince Tag: Preview of Document Tag: 62570
Custom printing options available through VBA?
I am just learning VBA printing options, so bear with my novice-ness. :)
I'm writing a snippet of code to automate a print job. As part of the job,
I would like to three-hole punch certain pages and staple others. These
options (three-hole punching and stapling) are available through the
PRINTER->PROPERTIES menu, but I do not see any language reference to this
area in VBA. Is it possible for me to automate access to "special" printer
functions through VBA? If so, how?
Thanks in advance for any help and/or advice. Tag: Preview of Document Tag: 62569
Formatting /Sorting Checkboxes
Hello.
I'd like to add checkboxes to a list questions on my document template/form.
Checked boxes are positive: Unchecked/blank boxes are negative.
That's the easy part.
Then I'd like to add a command that separates the negative from the positive
into two distinctly formatted sorted paragraphs and hides the original
block/list of questions.
DocNusum
--
PrimeCare PLLC
Primary Care in Your Home Tag: Preview of Document Tag: 62568
Finding a complete list of all character formatting
Dear colleagues,
Does anyone know were I can find a complete list of all character formatting
proporties that can be checked using VBA like bold, italic, underline, ...
?
(only the character style formatting, not the complete paragraph formatting)
Many thanx
JD Tag: Preview of Document Tag: 62566
Save each Word page as a separate document
Is it possible using VBA to create a separate Word file based on each page in
a larger Word document?
The larger document has many pages with headers and footers. Is it possible
to use the "Print to file" option? If so, how? If not, how can this be done
in VBA?
Thanks in advance. Tag: Preview of Document Tag: 62563
How to delete pages in MailMerge
Hi-
A week ago, I posted a question that was not successfully answered, so I'll
change my approach and rephrase it.
I have a rather long document that has many fields that are filled in by a
mailmerge. (MERGEFIELDs and DOCVARIABLEs gotten from several user forms,
where the user fills in OptionBoxs, CheckBoxs and TextBoxes).
MailMerge will generate the entire document, but if a certain question is
not answered, I want to delete some pages. If I can set up bookmarks around
these pages, can a macro be automatically run, and if the DOCVARIABLE is "Y",
then delete from BookmarkA to BookmarkB?
Alternatively, is there a better way of doing this?
Thanks,
Marty Tag: Preview of Document Tag: 62552
VBA copy and paste
I am working on an application using Word 2003. I am familar with VBA using
Excel and Access, but not with Word.
The application I am working on is a word doc that reads data in from a
database. It can be any number of pages long and each page will be in the
exact same format (consisting of tables, labels and text boxes). What I need
to be able to do is write a macro that on can copy and paste the first page
on to other pages, depending on how many are required (this will be done on
startup).
Can anyone help?
Thanks
Darach Tag: Preview of Document Tag: 62549
Renumbering superscript notes?
I'm wondering if it's possible to create a macro that will renumber all the
occurrances of superscipt consecutively--even if they're not using the
endnote or footnote function?
The reason for the last part is that I currently use a macro that unembeds
the notes and changes the note numbers to superscript. This way I can move or
renumber a note manually without deleting the corresponding text of the note.
However, it would be a great help if I could set up a macro that would, after
I'm finishing editing, go through the document and renumber all the notes
consecutively in case there's one that was missing, out-of-sequence, etc. Is
this even feasible?
Thanks in advance!
~Carrie Tag: Preview of Document Tag: 62544
Restoring bookmark in header/footer
Restoring a bookmark after changing its contents is a snap in the main
story of the document with ActiveDocument.Bookmarks.Add. Not so in
headers/footers. What's the secret there? Tag: Preview of Document Tag: 62543
formattedtext is not a reference error
I'm automating Word2003 in VB.Net. I'm using late binding.
I want to put another document's content into the selected area of the
active document, without loosing its formatting.
I'm getting a 'formattedtext is not a reference property' error with the
following code
... Selection.FormattedText = doc.Content.FormattedText ...
If this is a bug, does someone know another statement to achieve the same
result.
I'd like not to use clipboard.
--
thanks, gloeng Tag: Preview of Document Tag: 62537
The below macro will not stop at the end
Hello from Steved
How do I please put a argument in the below macro so that
when it gets to the bottom off the document it ends as at
the moment when it reaches the end it starts deleting
everything above until it deletes it all.
Thankyou.
Sub RaceDictionary()
Dim i As Long, pararange As Range
For i = 1 To ActiveDocument.Paragraphs.Count
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "'"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^$^$^$"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Extend
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^$^$^$"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=3,
Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Find.ClearFormatting
With Selection.Find
.Text = "\(*by"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=3,
Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.TypeBackspace
Selection.TypeText Text:="= "
Selection.EndKey Unit:=wdLine
Selection.TypeBackspace
Selection.TypeText Text:=", "
Selection.Find.ClearFormatting
With Selection.Find
.Text = "*$"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=1,
Extend:=wdExtend
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.Extend
Selection.Find.ClearFormatting
With Selection.Find.Font
.Size = 30
.Bold = True
End With
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
Next i
End Sub Tag: Preview of Document Tag: 62534
Opening a Goldmine email message from Word (using VBA)
I need to use VBA from Word to open a new Goldmine v.6.5 email message programmatically, and hopefully even go a step further and
attach a file or 2 to the new message. I'm not seeing much talk of VBA in the Goldmine forums so I'm kinda worried about now. I
really need this to happen. Can anybody help? I'm flexible and willing to give almost anything a shot. It is starting to appear that
Goldmine doesn't work and play well with others.
Thanks in advance.
--
RMC,CPA Tag: Preview of Document Tag: 62530
How to make doc's FullName into an AutoText entry without first inserting it into document
This macro works fine. It temporarily Inserts Fullname of the active
document into the document and makes that string an AutoText entry
called MyDocName, which is used later by another macro to reactivate
this document from another document. This enables me to return
instantly to this document without having to open the Window menu or
scroll through the open documents. But I wonder if there is a more
efficient way of doing it, so that the active document's FullName
doesn't actually have to be inserted into the document as a range, but
rather the FullName becomes an AutoText entry in one step. It seems
that would make the macro a little faster.
Any ideas? Thanks.
Larry
.
Sub DocFullNameStore()
Application.ScreenUpdating = False
Dim X As Long, Y As Long
Dim r As Range
X = ActiveDocument.Range.End - 1
ActiveDocument.Range.InsertAfter ActiveDocument.FullName
Y = ActiveDocument.Range.End - 1
Set r = ActiveDocument.Range(Start:=X, End:=Y)
NormalTemplate.AutoTextEntries.Add Name:="MyDocFullName", Range:=r
r.Delete
End Sub Tag: Preview of Document Tag: 62528
Problems deleting tollbar
'I want to make a new toolbar, and delete it. Problem is that it seems to be
deleted ,but
'every time I restart word it is back. If I run Sub createmytoolbar() 6
times it gives me 6
'toolbars after restart of Word ! The only way I can kill them is to delete
normal.dot!
'In word200, normal.dot i have created this
Sub createmytoolbar()
Application.CustomizationContext = NormalTemplate
Dim cBar As CommandBar
For Each cBar In Application.CommandBars 'ActiveDocument.CommandBars
If cBar.Name = "Mine" Then
MsgBox "Mine is there"
cBar.Delete
End
End If
Next cBar
MsgBox "We must make Mine!"
Call createmine
End Sub
Sub createmine()
MsgBox "Then iI have a routine for creating and it seems to work"
' routine
End Sub
What am I doing wrong??
arne Tag: Preview of Document Tag: 62525
.dot files get corrupted w/time, so iwhy not use Vb.net w/automati
I have found that template (.dot) files eventually get corrupted, and I have
to create new ones in which I re-create all my forms and macros.
Methinks it'd be a better idea for me to program all the macros and forms in
Vb.net, and to use (what I think is called) "automation" to manipulate Word's
built in functioning.
Am I missing something? Or is my perception "right"?
Any thoughts on this would be most welcome and appreciated.
Marc Hankin Tag: Preview of Document Tag: 62523
How do I create a button in a word template that will run a macro
I Have four fields that need to be updated when the template is opened and I
have recorded a macro
Selection.WholeStory
Selection.Fields.Update
Selection.HomeKey
Now I want to display a button that the user can click to run this macro so
he can update the fields.
is it also possible to print the pages individualy to individual pdf files
via a macro to be attached to an email later?
Thanks Tag: Preview of Document Tag: 62520
Formatting dates
Hi
I want to use VBA to rename some files with a date. Eg
for 30 Jan 2005 one file is renamed to "EN300105.txt" (eg
ddmmyy.txt)
I have used the following - which works, but actually
renames the file "EN3012005.txt" :
(eg it shortens the ddmmyy format - removes the 0 from
month, etc)
strDay = Format(Day(Now), dd)
strMonth = Format(Month(Now), mm)
strYear = Format(Year(Now), yy)
ActiveDocument.SaveAs FileName:="c:\temp\EN" & strDay &
strMonth & strYear & ".txt",
How can this be changed such that it is
renamed "EN301205.txt"
Thanks
Mat Tag: Preview of Document Tag: 62510
Word 2003 customised toolbar
I have a template which has an attached toolbar.
When a document is first created from the template, some of the
toolbar buttons are enabled and some are not.
When the buttons are used, a routine (UpDateToolbars) is called which
checks various conditions and enables or disables buttons according to
those conditions.
This works perfectly in Word 97 and Word XP.
In Word 2003, after the call to UpDateToolbars all of the buttons
appear as if they were disabled (greyed out) except occasionally when
they all appear as if they were enabled.
The buttons are "repainted" correctly if the cursor is swept over
them.
Forcing a screen refresh at the end of the UpDateToolBars procedure
does not correct this.
Any suggestions gratefully received.
Geoff Edwards
Leeds, UK
e-mail: stopspambot@sixwillow.com
(replace the stopspambot bit with some
version of my name) Tag: Preview of Document Tag: 62507
Problems with headers and footers - lengthy I'm sorry
Win 2K
Word 2K
Hi All
Thank you to anyone in advance who has the patience to read this. I have
tried everything and read tons in these groups to try and resolve the
problems, but I'm not sure there is a bullet proof way of doing what I need.
Here's the situation (I'll try to be brief but in fear that brief may not be
descriptive enough ....... here goes.... )
When a user presses Alt + S, an inputbox appears, the user is prompted for
the name of a witness, and the witness name is then inserted into the
document with a colon, two spaces and the word SWORN following their name.
Additionally, I bookmark the name for use in a table later on.
code snippet for Alt + S (NASTY but it works for now until I clean it up
hopefully with ranges)
**************************************************
Dim strSwornName As String
strSwornName = InputBox("Enter Name of individual being sworn")
'Inserts name of witness being sworn
With Selection
.TypeText Text:=StrConv(strSwornName, vbUpperCase) & ": " & "SWORN"
.ParagraphFormat.Space15
.EndKey unit:=wdLine
.HomeKey unit:=wdLine, Extend:=wdExtend
.Font.UnderLine = wdUnderlineSingle
.MoveLeft unit:=wdCharacter, Count:=1
.MoveRight unit:=wdWord, Count:=1
.MoveRight unit:=wdWord, Count:=1, Extend:=wdExtend
End With
strWitnessName = Left(strSwornName, 1) & ". "
strWitnessName = strWitnessName & Trim(Mid(strSwornName,
InStrRev(strSwornName, " ")))
'Marks Last Name as bookmark for header
strWitnessLastName = StrConv(Selection.Range, vbProperCase)
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, name:=strWitnessLastName
End With
'Marks Last Name as bookmark for table of contents
strFWitnessName = Mid(strSwornName, InStrRev(strSwornName, " ")) &
", " & Left(strSwornName, InStr(strSwornName, " "))
********************************************
When a user presses Alt +1 , I have the text "EXAMINATION IN CHIEF BY" + a
document property being placed at the current location in the document.
code snippet
********************************
With myRng
.Text = strChief & " "
.InsertAfter ActiveDocument.CustomDocumentProperties("PTitle") & _
ActiveDocument.CustomDocumentProperties("PLastName") & ":"
.Case = wdUpperCase
.Font.UnderLine = wdUnderlineSingle
End With
***************************************
In addition to typing the text, the current code takes the name of the last
bookmark it finds in the file (the name of a witness), moves to a specified
table( table 1), inserts the bookmarked text in the first blank row and
bookmarked text page number in a specific column which is determined by the
type of examination. (Alt + 2 enters the text "CROSS-EXAMINATION BY" ...
(thus specifying a different column). That part works just fine. (Not very
elegant, but here's the gist of it - there's more but I thought this would
be enough. This piece only takes care of the Examination in Chief)
************************************************
otable.Range.Rows(otable.Rows.Count).Range.Select
With Selection
.InsertRowsBelow 1
.Collapse (wdCollapseStart)
End With
myrow = Selection.Information(wdStartOfRangeRowNumber)
With Selection
.TypeText Text:=StrConv(Trim(strFWitnessName),
vbProperCase)
.MoveLeft unit:=wdWord, Count:=3, Extend:=wdExtend
.Font.UnderLine = wdUnderlineNone
.MoveRight unit:=wdCell
Selection.InsertCrossReference
ReferenceType:="Bookmark", ReferenceKind:= _
wdPageNumber, ReferenceItem:=strBN,
InsertAsHyperlink:=False, _
IncludePosition:=False
End With
*******************************************************
I also need the header on the page where EXAMINATION IN CHIEF or
CROSS-EXAMINATION BY appears to print in the header .. however in a
different format. If ALT + 1 is pressed and EXAMINATION IN CHIEF BY appears
in the body, then the header must read "FirstInitial LastName of Witness -
in Ch." minus the quotation marks. If ALT + 2 is pressed and
CROSS-EXAMINATION BY appears in the body, then the header must read
"FirstInitial LastName of Witness - Cr. Ex.".
I have created subroutines to assemble the names properly for insertion in
the header as they are actually coming from custom document properties not
formatted the way they need to appear in the header.
The difficulty I AM having is twofold:
Problem #1
The header on all pages from section 3 to the end of the document must
ALWAYS include at least the following:
1.
R. v Name of Defendant
in addition to what I have described above (the in-Ch. or cr-Ex).on the
third line
The number 1 is the page number and a period
The R. v Name of Defendant is a field in the header that looks like this:
{ DOCPROPERTY "Header1" \* MERGEFORMAT }
Problem #2
Although the text EXAMINATION IN CHIEF BY .... may appear on page 3, that
individual's testimony may well carry over several pages until he/she is
finally CROSS-EXAMINED. At the page where the text CROSS-EXAMINATION BY
appears, the header will once again change to reflect the fact that the
cross-examination has now begun on that page. The page number and R. v Name
of Defendant must remain in the header and if the examination in chief
appears on the same page, that text must also remain in the header. I will
then need "FirstInitial LastName of Witness - cr-Ex." to appear on a fourth
line in the header.
Once a new witness is sworn in, the process begins again. That is, the
EXAMINATION IN CHIEF will have to be re-set in the header until the witness
is cross-examined etc. etc.
The document will continue to proceed in the same manner as potentially
hundreds (although that's probably excessive) of witnesses could testify.
Thank you to anyone brave enough to have read all this and further, have any
suggestions or recommendations.
Please let me know if I can clarify anything or whether I could have somehow
posted this in an easier to read format.
Legal jargon mixed with vba???? .... am I NUTS?
Debra Tag: Preview of Document Tag: 62504
Legacy Access2/VB4 app merge errors with Word 11
I have a network where all of the client machines were recently replaced and
are now running XP Pro SP2. Office 2003 is also on the new machines.
The legacy application was written in VB 4 and I have no source code
available. The Access version is 2.0. The application works as expected
and as it did before the upgrade with the exception of Microsoft Word
merging capabilities. The application creates a proper ".dat" merge
document but is unable to do the link. The .dat file contains a properly
generated header with the field names tab separated and the data from the
requested record (by entering the keycode value in a message box) tab
deliminted as well. The data is what it should contain.
The setup settings are properly directing the application to the correct
directory path and winword.exe file name. Word does not open and three
errors occur in succession according to the messages that appear:
In the title bar of the message box: "Merge Error (Word) #1056 and in the
center of the message box: "Not a valid filename."
Clicking on the OK command button brings up another error message box with
the title bar showing "31031 (0)" and the text in the message box being
"Invalid Source for link"
Clicking in the OK command button brings up another error message box with
the title bar showing "31004(0)" and the text in the message box being "No
object."
The document is a valid document and the path is correct. I have written a
workaround macro in VBA of Word to allow them, after responding OK to the
three messages in the legacy Access app, to press Alt-M in an open,
no-document Word application which presents them with the directory
containing the master merge document and containing the newly created data
source .dat file containing the header and record data as requested in the
legacy app. After selection of the requested file, I test the file name of
the .doc file and create a DataSourceFileName for .dat files over 8.3 and
then do the merge of the document to a new file with the .dat file created
and given as the source for the master document. This process proceedes
without a problem. I suspect that there may be some ODBC connectivity
problems between the legacy apps that don't know OLE and that are looking
for another type of data source other than ".dat" files. This was the old
way of providing a data source from which to merge via ODBC (to fake it out)
and the older DDE application connectivity.
I do not have the old app source code, the developer are not at all
interested in updating to anything later than Access 97 (believing that Bill
Gates is out to destroy them <bg>. Is there anything I can do, other than
writing a new application, to allow the users to merge with this old
application to Word v. 11? I have no problem accessing the tables via a
DSN-less SQLConnect() statement but the record comes through some 24 steps
in a "Logic" table in a different database than the actual data. I have
been doing database programming for 17 years but have little, brief
experience with Access but quite a bit with VBA, Visual FoxPro, SQL, and C.
It has been suggested that I write a dummy application in VB6 to impersonate
Word 6 and receive the file names passed and then use those and call Word 11
from this dummy app, passing the merge file and data source file names to
Word 11 on startup. I don't know how I'd go about "impersonating Word 6"
and create this "DDE sink" that's been suggested.
Any suggestions for any approach would be greatly appreciated? The
work-around is getting the users to the goal line but it's taking too many
downs to do make the
touchdown.
Justice Tag: Preview of Document Tag: 62497
Finding bad formatting
Dear people,
For some time now, I'm struggling to solve a VBA problem.
Some of you already gave some assistance, for which I'm great full.
I'm trying to find some bad formatting in a word document using VBA.
On all paragraphs are paragraph styles applied. On pieces of some
paragraphs, are Character styles applied. On other pieces of text, other
manual formatting is applied like "bold" or "Bold Italic".
I'm trying to detect the pieces of text that has no "character style"
applied and yet have other manual formatting is applied like "Bold Italic".
For example:
Some text is set to bold, this is wrong.
Other text has the character style "BOLD" applied, this is good.
I need to highlight all the bad formatting.
Can anyone please help me?
Thanks
JD Tag: Preview of Document Tag: 62495
disable some shortcut key's
Hi
Does anyone know how to disable some shortcut key's like ...
CTRL + F3
CTRL + SHIFT + F3
CTRL + "2"
Thanx
JD Tag: Preview of Document Tag: 62494
msmapi32.ocx vba vb problem
I made a mail application in word vba. It works fine but I didn't know that
someone installed vb 6 on my computer. Other people want to use the
application too and the activeX control: MSMAPI32.OCX is missing. Can I put
that ocx on a network drive. Those people dont have administrator rights and
can't install applications, only NAL-objects. A solution is making an exe
with the vb 6 wizard but to install that you must have rights to do that.
Does anyone know a solution. Put it in c:\windows\system32 or run a register
program in vbs code or something?
If I place the ocx on a drive on a user computer and click the microsoft
MAPI controls in the toolbox and choose the directory with the ocx it works
so it has not to bee registered or licensed, am I right??? CDO doens't work
it hits the firewall...
Thanks, Siebe Tag: Preview of Document Tag: 62491
disable toolbar buttons
Hi everyone,
Does anyone know how to disable some toolbar buttons (so they apprear to be
gray) using vba ?
For example ..
the italic-, bold- and underline-buttons
the font-popup in the toolbaar...
Thanx
JD Tag: Preview of Document Tag: 62486
Deleting a page forcibly
Hi,
I want to delete a particular *real page*.
Like many times if I copy data from let's say Web/ some software etc and
paste in to Word (I use word for Printing only !!!) then the last page would
be having no data (atleast it would be blank as far as am able to see) but
still even if am sitting on the period after the last letter in the Main
Story and if i keep pressing delete the Last page just wouldnt get deleted.
Why does this happen?
Is there a VBA solution to it (and yes, would be happy to know non-VBA
solution as well)
Thanks a lot,
Hari
India Tag: Preview of Document Tag: 62475
Find string in table and move to next cell
Hello All
Windows 2K
Word 2K
I'm trying to locate a string (strFWitnessName) in a table in my document
and then move one cell to the right to enter a page number.
strFWitnessName could appear in 1 of three tables in the document ( but it
will never appear in all three)
I do not want to search the entire document as strFWitnessName will appear
throughout the document text as well.
I found the following code posted by Doug Robbins and tried testing it but
apparently I am just not familiar enough with vba to understand what it is
doing.
Dim i As Integer, j As Integer, myrange As Range
For j = 1 To ActiveDocument.Tables.Count
For i = 1 To ActiveDocument.Tables(j).Rows.Count
Set myrange = ActiveDocument.Tables(j).Cell(i, 1).Range
myrange.End = myrange.End - 1
If myrange.Text = strFWitnessName Then
ActiveDocument.Tables(j).Cell(i, 2).Range.Text = "pagenumber1"
ActiveDocument.Tables(j).Cell(i, 3).Range.Text = "pagenumber2"
End If
Next i
Next j
Any help would be greatly appreciated.
TIA
Debra Tag: Preview of Document Tag: 62470
Special character not recognized
ActiveDocument.Bookmark("mybookmark").Range.InsertAfter "text"
where texts are texts that has special character created through
Insert>Symbol>ShortcutKey method.
How do I get around this problem? Tag: Preview of Document Tag: 62469
AddressLayout
I was attempting to eliminate the United States of America for addresses
when I import an address from Outlook. Somehow in the process "United States
of America" got substituted for the zip code. No matter where I place the
{<PR_POSTAL_CODE>} in the address form, it comes out "United States of
America" I assume there is a table somewhere that sets forth those codes.
Any ideas.
Nick@nicksigur.com Tag: Preview of Document Tag: 62467
automatically close a doc after user clicks on email send?
Hi All
I have a word form ready with the email header active in the document. When
I select Send on the email, the document remains open. I would like it
automatically close once the send button is hit. I found that the
ActiveWindow.EnvelopeVisible toggles the word email header.
I have got this far via the web but I really have no idea:
created a Class Module -clsobject:
Public WithEvents oApp As Word.Application
Private Sub oApp_DocumentChange()
' dunno what to put here
End Sub
created a module:
Dim oAppClass As New clsObject
Public Sub AutoExec()
Set oAppClass.oApp = Word.Application
If ActiveWindow.EnvelopeVisible = False Then
ActiveDocument.Close
End If
End Sub
Any ideas? Thanks in advance Tag: Preview of Document Tag: 62456
SetFocus on a userform Does Not Work
I have a fairly simple userform with a frame and two
textboxes inside the frame. If a user makes an invalid
entry I want to display a message, clear the entry, and
set the focus back to the same field.
The mesgbox displays perfectly, and the entry is cleared
fine. However, the focus keeps going to the next textbox
in the frame. I am getting frustrated! I even tried
setting the focus back to the frame first, and then to the
field. I also tried using the Exit event with no success.
I am using the AfterUpdate event and the name of my
textbox is txtClientNumber. My code appears below.
Any ideas would be apprecaited. Thanks so much in advance.
Private Sub txtClientNumber_AfterUpdate()
Dim StrClientName As String
Dim rstClientName As ADODB.Recordset
Set rstClientName = New ADODB.Recordset
StrClientName = "SELECT client_name FROM hbm_client
WHERE client_code = '" & txtClientNumber.Value & "'"
rstClientName.Open StrClientName, Main.cnn
If rstClientName.EOF = True Then
MsgBox "That is an Invalid Client Number"
txtClientNumber.Value = Null
frmMain.fme1.SetFocus
txtClientNumber.SetFocus '***PROBLEM HERE
Else
rstClientName.MoveFirst
txtClientName.Value = rstClientName
("client_name").Value
End If
End Sub Tag: Preview of Document Tag: 62453
Printing pictures in Word
if i insert a picture at say 12cm x 12 cm, word prints it at around 10.5cm x
10.5cm
It looks like the page is set up smaller than it should be, but its set up
for A4
Help please
Thanks in advance, Snaff Tag: Preview of Document Tag: 62452
Can't add a reference to the specified file
Here's one for the Google archive, in case anyone else hits it.
On my development machine, I began getting an error when attempting to
set a reference within a Word VBA module to another Word template. The
error was:
Can't add a reference to the specified file
The template I was trying to set a reference to was one I have been
using for over a year without a problem. My machine gets pretty badly
beaten up while I'm coding and debugging, so no doubt I fried
something. Now here's the strange thing. The template to be referenced
was:
c:\My Programs\Foo\Foo.dot
The precise symptom: start word, hit Alt+F11, open a module, choose
Tools, References, navigate to and select the Foo template. PRANG!
Error.
Exit Word. Rename either the template *or* the folder *or* the folder's
parent, and everything works! E.g.:
c:\My Programs\Foo\FooA.dot -- no problem
c:\My Programs\FooZ\Foo.dot -- no problem
It was only when the template full path was
c:\My Programs\Foo\Foo.dot
that the error occurred. Very bizarre!
I reinstalled MS Office, cleaned the registry of all references to Foo,
but no joy.
It turned out that the problem was somewhere inside my XP profile. When
I logged in as another user, everything worked. I simply renamed my old
profile, then logged in as myself again. Presto! Problem solved. (I had
to harvest my favorites, Start menu, etc. from my old profile, but it
sure beat nuking and rebuilding the machine.
Hope this helps someone else. Tag: Preview of Document Tag: 62448
How do I get data from MySQL ?
Is there a way to get data from a MySQL database? Then can I insert the data
into Word in some non-table format? I want to be able to place some data
within paragraphs of my document. Tag: Preview of Document Tag: 62447
When sending a word document in an email i get an error "word can.
I'm trying to send a word document in an email when i get an error. The error
says "Word Cannot load the Email envelope". Why am I getting this error and
how do i fix it? Tag: Preview of Document Tag: 62446
Calculating in VBA
This expression tells me which page I'm on:
Selection.Information(wdActiveEndPageNumber)
I want to do something if a page is odd or something different if it
is an even number.
Is there a way of doing this in VBA, please?
I was looking for something that would allow me to divide a page
number by 2. If the remainder was not zero then it must be an odd
number. That's my logic but I cannot work that in VBA.
Regards
Roderick O'Regan Tag: Preview of Document Tag: 62442
Unable to insert word html file into a Word document
Hello,
I have a HTML document created by saving the document with Word using the
wdFormatHLMLFiltered. This works fine and I can see the document. However,
if I attempt to insert this HTML file into another word document I only see
the first line of the document. Is there some sort of restriction from
using wdFormatHTLFiltered and other word documents?
Thanks,
Jerry Tag: Preview of Document Tag: 62441
What is wrong with this code?
Hello,
I´m trying to paste two cells (text) from Excel to Word. The code pasted
below does not completely do the trick - please could someone tell me what
is the problem, what must be added?
Problems:
1. If I leave out the ".Collapse wdCollapseEnd", the range A1:D1 gets
replaced by the range A2:A6. Then the range A2:A6 is formatted like I want
it to be (bold).
2. If I dont leave it out, the formatting is not correct, but both ranges
are being copied otherwise correctly. Then the range A2:A6 is not being
formatted at all, but copies the formatting from range A1:D1 (not bold).
Sub TW()
Dim AppWD As Word.Application
Dim DocWD As Word.Document
Dim RangeWD As Word.Range
Set AppWD = CreateObject("Word.Application.10")
AppWD.Visible = True
Set DocWD = AppWD.Documents.Add
With DocWD
Set RangeWD = .Range
Sheets("T").Select
Range("A1:D1").Select
Selection.Copy
With RangeWD
.Font.Name = "Arial"
.Font.Size = 12
.Font.Bold = False
.PasteAndFormat Type:=wdFormatPlainText
.Collapse wdCollapseEnd
Sheets("T").Select
Range("A2:A6").Select
Selection.Copy
With RangeWD
.Font.Name = "Arial"
.Font.Size = 12
.Font.Bold = True
.PasteAndFormat Type:=wdFormatPlainText
.Collapse wdCollapseEnd
End With
End With
End With
End Sub Tag: Preview of Document Tag: 62439
Word Templates
Can word templates be lock down or controlled? What we are looking for is
locking down the template and let users change content of the templates.
Also, if the template changes, then what happens to the old content? Tag: Preview of Document Tag: 62432
I amusing WORD 97.
Can anyone assist me with some code for a userform which creates a preview
picture of a document.