Opening word files from Samba share is very slow??
Hi Folks,
We've been having problems with opening word files from a samba share in
that it takes forever to open and as a result some AutoOpen macros fail
to execute properly.
The macros work in other environments and in similar environments to our
problem area which is -
Windows 2000 Pro
Office 2000 Pro
Novell Client
Sophos Anti Virus
Samba shares mapped at logon
Over 100MB Network
Any ideas would be appreciated.
Cheers
J Tag: Sharing macro ind Word 2003 Tag: 61574
How to customize the pop-up right-click menu in MSword?
Using Word macros I have added two options to the right-click popup
menu of MSWord. I want only Option1 to be displayed when the cursor
points to a bookmark and option2 to be displayed when the cursor is
placed on a normal line (not a book mark).
How to customize the popup menu? Tag: Sharing macro ind Word 2003 Tag: 61568
Wd2003:AutoExit Macro Doesn't Restore Menu Items Customized by Aut
I use a customized word 2003 template. In the AutoNew macro, I'm saving the
commandbar settings in registry, deleting all commmandbars and creating some
customized command bars. When the application is closed, the commandbar
settings saved in the registry has to restored. I do it in the AutoExit
macro. Apparently, this is not working. (This was early in Word 97. It was
working fine.) When the AutoExit function is called, the commandbars are
being reinstated, but once the word exit and I open word again, they are not
gone.
For word 2000, microsoft have given the solution as to open the normal
template and make the menu changes and save it. But this is not working in
this case. Tag: Sharing macro ind Word 2003 Tag: 61561
Word Macros
hi,
Using Word macros I have added two options to the popup menu. I want
only Option (1) to be displayed when the cursor points to a bookmark
and only option (2) to be display when the cursor is placed on a
normal line (not a book mark)
How to customize the popup menu?
Can anybody tell me how to resolve this problem?
Thank you
Petricia Smith Tag: Sharing macro ind Word 2003 Tag: 61560
Preserve numbering when copying to a new document (MVP)
Hi there!
I need to copy paras formatted with styles containing outline numbering
(legal) to a new document and retain the numbering (using VBA)....
I seem to lose some of the numbering.
Ideas most welcome.
Thanks
Tim Tag: Sharing macro ind Word 2003 Tag: 61559
Removing trailing carriage returns in Word VBA?
Okay, so I've got a macro that's supposed to concatenate a bunch of
documents together, separated by exactly one blank line. The thing is,
I can't count on any specific number of blank lines at the end of each
source document that I'm concatenating. It would be nice if, after I
append each document to my master document, I could remove all trailing
carriage returns from the master document, so that I'll know exactly
where I am and how many blank lines I'm going to have after each
append.
I've scoured the books and newsgroups, and I haven't found a way to do
this. It seems simple enough, so maybe it's just my brain shorting out
after a long day. If anyone can shed some light on this, I would
vastly appreciate it.
~ Steve Tag: Sharing macro ind Word 2003 Tag: 61556
Copy Word lines into an array?
I accidentally posted this question in another NG, please disregard the other
one.
I need an example function that will copy each line in a Word document
beginning at the first line and ending at the end of paragraph 10. Each line
needs to be separately copied into an array.
Can someone please, please, please post a function to do this? Thanks so
very much in advance. Tag: Sharing macro ind Word 2003 Tag: 61553
Obtain the index number of the active document.
I know how to get the count of active documents and the active document name.
I'd like to extract the index number of the active document.
Any suggestions?
TIA Tag: Sharing macro ind Word 2003 Tag: 61548
Highlight regions of protected document
This applies to Word 2003
Is there a way to programmatically turn off the "Highlight regions I can
edit" option that is accessible from the Protect Document task pane of a
protected document? I do not want this option selected when a user opens the
document.
Thanks. Tag: Sharing macro ind Word 2003 Tag: 61540
How can I force to change cursor under unselected fields?
I have a set of fields type of "wdFieldMacrobutton". And the problem is that
on roll over event the cursor changes to arrow only if the field is selected.
How can i make cursor change to an arrow under not selected fields? Tag: Sharing macro ind Word 2003 Tag: 61538
how to send e-mail
What code could I use to send an e-mail message.
I've generated all events and I just need this code to send the e-mail.
Private Sub oApp_DocumentBeforeSave(ByVal Doc As Document, SaveAsUI As
Boolean, Cancel As Boolean)
Dim strFileName As String
strFileName = ActiveDocument.FullName
??? Code for the e-mail that in the strFileName some changes have been made.
Thanks Tag: Sharing macro ind Word 2003 Tag: 61537
HELP - Tabs and Paragraphs
Hello all,
Would anyone have any suggestions on this? When I start at
the very end of each line preceding each of the (2)
examples below, there is (1) chr(13) for a paragraph mark
and (2) chr(9) for a tab mark. But on line one, you only
go to the beginning of the line and with line 2 you go
over to the Tab2 position. I am guessing that the tab must
have some kind of properties that tells Word to go over to
the tab2 position, but darn if I know what it is.
If anyone could offer any suggestions, it would be greatly
appreciated!
Tab 1 Tab 2
>> Line 1 Some Text Some other text
>> Line 2 Yet more text Tag: Sharing macro ind Word 2003 Tag: 61533
Move IP to the start of a Story
Hi,
ActiveDocument.Range(0,0).Select
moves the IP to the start of the maintext story apparently from any
story.
My IP is in the header story and I want to move the IP to the start.
I can use
Selection.HomeKey Unit:=wdStory
I was wondering if there isn't a Range(Start, End) method that I should
be using.
Thanks Tag: Sharing macro ind Word 2003 Tag: 61532
renaming class or module in a project window in VB
How to rename a class or module in a project window in VB?
The Module1 to something name and the Class1 to something name?
Thanks Tag: Sharing macro ind Word 2003 Tag: 61522
Letting others use routines I've written
My VBA programming has always been only for myself, up to now. But I've created a document conversion program that is needed by others, and I cannot get it to work on their computers. I copied the template to a network drive, then copied from there to Word's Templates directory on a co-worker's computer. Then I attached it to the document that he wanted to convert, but when I bring up the Macros dialog, the list of macros is blank, even when I specify the template name in the "Macros in" box.
So there's something I'm missing about the VB environment. Also, it would be nice if, on other machines, users did not have to first attach the template to the document before using it. Any help appreciated.
Christopher Brewster
Lockheed Martin
--
Message posted via http://www.officekb.com Tag: Sharing macro ind Word 2003 Tag: 61520
Appendix in TOC
Hi
I am working with Word 2002. I have created a document and added a table of
content. Fine. But it does not pick up my appendix (it is in a separate
section, page break). How do I get the TOC to include thr appendices? Tag: Sharing macro ind Word 2003 Tag: 61518
How can I insert data from a word document in a Access database?
I need some help to know what I have to do to insert somo information from a
Word Document in a table from an Access database. Do I have to create a Macro?
If yes, How can I type the code? Tag: Sharing macro ind Word 2003 Tag: 61516
Unwanted control toolboxes
In Word 2000 VBA control toolboxes appear in the upper left and lower
right corners, unbidden, when documents are opened. The lower right
toolbox shows only a triangle.
What causes this and how can I get rid of it? Tag: Sharing macro ind Word 2003 Tag: 61515
Word install problem
my office got uinstalled by some reasons I dont know. so now I cant open it!
every file is on the harddisc but I cant find any install program:S can
somebody help me???? Tag: Sharing macro ind Word 2003 Tag: 61513
Word install problem
my office got uinstalled by some reasons I dont know. so now I cant open it!
every file is on the harddisc but I cant find any install program:S can
somebody help me???? Tag: Sharing macro ind Word 2003 Tag: 61512
Word Install-problem
Hi.. my office by some reasons got uinstalled! but i can find the program to
install office again, and I dont have some CD`s of I need that. can somebody
help me please? Tag: Sharing macro ind Word 2003 Tag: 61510
How do I set TOC Page Numbering with (Page x of y) and sections?
Per article 291283 "How to create two page-numbering schemes in one document
in Word 2002" - how do I set correct page numbering for the
Table of Contents?
I was successful in using the Method 1, "Use SEQ fields", but that causes
the numbering in the TOC to start at 1 for every section listed, instead of
showing the real page number based on the total number of pages.
Any help in writing the necessary code will be greatly appreciated.......! Tag: Sharing macro ind Word 2003 Tag: 61503
How to automatically update the Filename field?
How do I get the Filename field in different headers of a protected form to
automatically update when closing the form? The Filename field is in all of
the different headers in the form. This was a default feature of Word 2000,
but is not a feature of Office 2003. Thanks. Tag: Sharing macro ind Word 2003 Tag: 61502
How to automatically update the Filename field?
How do I get the Filename field in different headers of a protected form to
automatically update when closing the form? The Filename field is in all of
the different headers in the form. This was a default feature of Word 2000,
but is not a feature of Office 2003. Thanks. Tag: Sharing macro ind Word 2003 Tag: 61501
Adding Meetings to a Word Doc.
I have a word document that gets sent out to a bunch of people, which
contains meetings. I would like to set up a way so that they can click
on a meeting and it would add the meeting to their outlook calendar as
a meeting. Hope that make sense. Tag: Sharing macro ind Word 2003 Tag: 61496
Changing Invoice # automatically on document
I am using the templates in word for invoices. Is there a way I can set up
the invoice # to change everytime I print/save a new invoice.
I just started using these invoices thru Word so any other suggestions would
also be helpful.
So far, I have set up the template and added form fields. Upon exiting I am
saving each one into a folder for the month of that year.
Thank you Tag: Sharing macro ind Word 2003 Tag: 61487
Forms - Protecting Sections
Hello all,
I have created a Word 97 form which is basically in 2 parts. The first
section contains numerous fixed fields and drop down boxes and this section
is protected. The second section is an area for freeformat text and so is
unprotected. Within the form I have a Macro which when activated copies
sections 1 and 2 and creates sections 3 and 4 the first time, 5 and 6 the
second time, etc. After the Macro has run I need to reprotect all odd
numbered sections and leave all even numbered sections available for
freeformat text. Is there any way to do this?
ActiveDocument.Sections(all odd numbered sections).ProtectedForForms = True
ActiveDocument.Sections(all even numbered sections).ProtectedForForms =
False
ActiveDocument.Protect Password:="", NoReset:=True, Type:= _
wdAllowOnlyFormFields
Grateful for any assistance.
Paul.
PS low level knowledge of VBA - use the recorder to perform the bulk of the
action and then edit a bit where necessary. Tag: Sharing macro ind Word 2003 Tag: 61486
Word template only works on one PC
I have a Word 97 template file (i.e. .DOT file) that is on a particular PC
in our office. The template uses VBA to connect to an Access database
(located
on a server share) and creates a document based upon some data. When I
simply move the particular .DOT file to any other PC and try to create a new
file using that template, part of the code fails. When I launch the VBA
editor for the template file on the working PC there are several items that
I can see that I cannot see when I launch the VBA editor for the template on
any other PC:
1) A Modules node under the Normal node that has two modules in it. I can
click on these and examine the code.
2) Three additional TemplateProject folders. Although, when I try to view
the code for these TemplateProject folders I get a dialog box that says
"Project is unviewable".
I can tell, based upon the name of one of the TemplateProject folders, that
the template VBA code fails (it's a call to WordBasic.Call) on every other
PC because these TemplateProject folders (as well as the aforementioned
Modules) don't seem to exist on those PCs. So, my basic question is why can
I see these VBA project elements on the working PC, but not on any other
PCs? I assume there must be some files and/or environment settings on the
working PC. Any help would be much appreciated.
Thanks. Tag: Sharing macro ind Word 2003 Tag: 61485
Speed-up merge empty cells in msword tables
Hello,
I have a small VBA code that merge empty cell on each rows but keeping the columns.
For example the table:
---------------------
|A | B | C | D | |
---------------------
| | B | C | D | |
---------------------
| | B | C | D | |
---------------------
|A2| B2| C2| D2| |
---------------------
| | B2| C2| D2| |
---------------------
will be converted to
-------------------------
|A | BBB | CCC | DDD |
|A2| B2B2| C2C2| D2D2|
-------------------------
The problem is that it takes a very long time for tables with more than 50 rows.
Do you have any ideas on how to speed-up this macro?
Thank you,
Catalin Florean.
'My macro:
Sub tmpTable()
Application.ScreenUpdating = False
cateMerge = 0
Set myTable = ActiveDocument.Tables(1)
cateCol = myTable.Columns.Count
cateRow = myTable.Rows.Count
For currentRow = 1 To cateRow
If Len(myTable.Cell(currentRow, 1).Range.Text) <= 2 Then
cateMerge = cateMerge + 1
For j = 1 To cateCol - 1
myTable.Cell(currentRow, 0).Merge MergeTo:=myTable.Cell(currentRow - cateMerge, j)
Next j
Else
cateMerge = 0
End If
Next currentRow
myTable.Columns(cateCol).Delete
Application.ScreenUpdating = True
End Sub
--
Message posted via http://www.officekb.com Tag: Sharing macro ind Word 2003 Tag: 61484
Speed-up merge emply cells in msword tables
Hello,
I have a small VBA code that merge empty cell on each rows but keeping the columns.
For example the table:
A B C D
BB
'My macro:
Sub tmpTable()
Application.ScreenUpdating = False
cateMerge = 0
Set myTable = ActiveDocument.Tables(1)
cateCol = myTable.Columns.Count
cateRow = myTable.Rows.Count
For currentRow = 1 To cateRow
If Len(myTable.Cell(currentRow, 1).Range.Text) <= 2 Then
cateMerge = cateMerge + 1
For j = 1 To cateCol - 1
myTable.Cell(currentRow, 0).Merge MergeTo:=myTable.Cell(currentRow - cateMerge, j)
Next j
Else
cateMerge = 0
End If
Next currentRow
myTable.Columns(cateCol).Delete
Application.ScreenUpdating = True
End Sub
--
Message posted via http://www.officekb.com Tag: Sharing macro ind Word 2003 Tag: 61483
Speed-up merge emply cells in msword tables
Hello,
I have a small VBA code that merge empty cell on each rows but keeping the columns.
For example the table:
A B C D
BB
'My macro:
Sub tmpTable()
Application.ScreenUpdating = False
cateMerge = 0
Set myTable = ActiveDocument.Tables(1)
cateCol = myTable.Columns.Count
cateRow = myTable.Rows.Count
For currentRow = 1 To cateRow
If Len(myTable.Cell(currentRow, 1).Range.Text) <= 2 Then
cateMerge = cateMerge + 1
For j = 1 To cateCol - 1
myTable.Cell(currentRow, 0).Merge MergeTo:=myTable.Cell(currentRow - cateMerge, j)
Next j
Else
cateMerge = 0
End If
Next currentRow
myTable.Columns(cateCol).Delete
Application.ScreenUpdating = True
End Sub
--
Message posted via http://www.officekb.com Tag: Sharing macro ind Word 2003 Tag: 61482
speed up vba
I use a small vba routine to create new documents. the macro opens an
empty document and then adds a few objects (e.g. logo image, header and
footer text boxes, etc). some text may also be added.
This whole procedure takes about 10 sec, which i find very long time for
just the few thing to do. A simular procedure in PowerPoint runs in less
than 1 sec!
Are there any hints how I can speed up my macro? Turning off
ScreenUpdating didn't help much.
Thanks a lot, Luc Tag: Sharing macro ind Word 2003 Tag: 61478
Word and Internet Server documents.
Hi,
Some time ago, I asked a question concerning slow response when opening a
Word document from an Internet server for the first time. All subsequent
Word document openings were pretty quick. Someone responded, in very
technical language, about SOEs and XCOPY to "prime" the network and caching.
However, despite my gentle prodding, he did not elucidate, or distance
himself from the abstract or the deeply technical. However, he did raise my
hopes that there might be a solution. So here, below, I present my problem,
in the hope that someone can be more specific about a solution.
----
I have an ASP page which generates a XML (wrapped in HTLM) file which
represents a Word document. Then, from the client side of the Internet
connection, I open this newly created document using Word. When first this
process runs, following a machine re-boot, it can take up to a minute to
complete. Thereafter, it takes 3 seconds.
The Word command is something like :
Set objWord = CreateObject("Word.Application")
Set doc = objWord.Documents.Open(http://localhost.service/document.doc)
------
Is it true that the network and caching needs priming? If so, does anyone
know how to "prime" such, or know of any Web pages that might tell me how.
I'm using IIS, under XP, and Word 2000.
Many thanks
Gem Tag: Sharing macro ind Word 2003 Tag: 61475
Set details view in Open Document Dialog as Default
Is it possible to set the default view to Details View in the
Open/New Document dialog with a macro?
If thats' the case - any code example?
--
Anette Tag: Sharing macro ind Word 2003 Tag: 61474
Track Changes: Deleted text is red, not strikethrough
I'm using Word 2002 (10.6612.6626) SP3 on a WindowsXP computer.
When I create a document and activate Track Changes, text that I delete
turns red instead of strikethrough. When I send the document to another
person, the deleted text is marked as strikethrough when they open it in Word
(same OS and version of Word) instead of red.
I much prefer strikethrough text over red text.
I've tried the fix in described this article (wdFixStrikethrough):
http://support.microsoft.com/default.aspx?scid=kb;en-us;323883
This article mentions deleting a data key in the registry, but does not say
WHAT key.
I've also searched the user groups for information and visited several MSVP
sites with no success in finding a fix.
Can anyone help me with this. Tag: Sharing macro ind Word 2003 Tag: 61458
Notification about any changes in document
How can I send a notification about any changes in a document?
I think, it should be some after_update event but I don't know how I can
apply it to the Word document.
In addition, how I can assign the name of the changed document to strWordFile?
DoCmd.SendObject acSendReport, "rptNotofy", acFormatRTF, "Alex", , , _
"Some changes done in " & strWordFile, _
"Notification about changes done", False
Thanks in advance Tag: Sharing macro ind Word 2003 Tag: 61454
font change
I use the following code to insert a template with 'times new roman' font.
When I get thru the font is 'arial'. So what do I do to keep the 'times new
roman' font. TIA
Selection.InsertFile FileName:="c:\program files\microsoft
office\templates\newnewsletterrpl.dot", Range:="", _
ConfirmConversions:=False, Link:=False, Attachment:=False
Selection.GoTo What:=wdGoToBookmark, Name:="region"
Selection.Find.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.TypeText Text:=rstProj![project region]
Selection.TypeParagraph
Selection.TypeBackspace
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.HomeKey Unit:=wdLine
End If
--
_________________________________
in Christ's matchless name
73 ted & colleen
n6trf kc6rue Tag: Sharing macro ind Word 2003 Tag: 61452
Macro ms-word 2000
hi,
An Macro document is created in word 2003, the document file run marco fine
on ms-office Xp and ms-office 2003, but it generates 2 errors while running
the word document on ms-office 2000. Error (1) Compile Error in hidden module
and (2) this is not a valid file name try one or more of the following *
check the path to make sure it was typed correctly. * Select a file from list
of file and folders.
please provide a valid solution if you need the document, shall email on
response.
thanks Tag: Sharing macro ind Word 2003 Tag: 61451
Inserting AutoText in Header adds extra paragraph marks
I am trying to insert AutoText into Headers in my document.
I carefully selected just what is needed to create the
autotext, but when I insert the autotext into the header
it adds an extra paragraph mark (the mirrored 'P').
This cause problems because all my document gets reflowed.
Can somebody please help me figure out how I can either
delete the paragraph marks or have them not be inserted
in there in the first place please?
My current code to insert the autotext is the following
ActiveDocument.AttachedTemplate.AutoTextEntries _ ("myAutoText").Insert
_
Where:=ActiveDocument.Sections(i).Headers _
wdHeaderFooterPrimary).Range, _
RichText:=True
the 'i' is the index for the loop that goes through all
my sections.
I have also tried to add a delete line before that command
but that didnt help either. I used
ActiveDocument.Sections(i).Header _
(wdHeaderFooterPrimary).Range.Delete
I have checked and rechecked and as far as I can see
my autotext (which includes its style) does not have
the extra paragraph marks.
How can I avoid these marks in the first place or
how can I convert the following code to work inside
the ranges?
Selection.EndKey Unit:=wdLine
Selection.Delete Unit:=wdCharacter, Count:=1
This would do what I need.
thanks for the help. Tag: Sharing macro ind Word 2003 Tag: 61446
Document( ).Activate
I have an open document. I then use VBA to open a second document
Sub Test()
Dim SecondDocument As Document
Set SecondDocument = Documents.Open(FileName:="C:\Word List.doc")
'Why do I have to use (2) below to activate the first document? I
seems like the original opened document would be (1).
Documents(2).Activate
End Sub Tag: Sharing macro ind Word 2003 Tag: 61445
Correct way to get Function's output into macro?
Thanks to someone whose name I have forgotten, I have a Function that
returns a folder name and puts it into a string variable. I call the
function in a macro to allow me to browse to a specific folder. At the
moment, the only way I have of getting the string back into the macro is to
declare the string variable at the beginning of the whole module. I'm aware
this isn't best practice, although it works. But how else do I get the
string from the function into the macro?
Ed Tag: Sharing macro ind Word 2003 Tag: 61444
object variable not set error in Word macro intermittant
Hello-
I am getting intermittant "error91" messages with this code which operates a
macro to open a 2 separate files, copy all text contents, close and then
paste into the active document.
Sub Macro01040and1050()
ChangeFileOpenDirectory "P:\Spec\"
Documents.Open FileName:="01040.doc", ConfirmConversions:=False,
ReadOnly _
:=False, AddToRecentFiles:=False, Revert:=False, _
Format:=wdOpenFormatAuto
Selection.Copy
ActiveWindow.Close
Selection.Paste
Documents.Open FileName:="01050.doc", ConfirmConversions:=False,
ReadOnly _
:=False, AddToRecentFiles:=False, Revert:=False, _
Format:=wdOpenFormatAuto
Selection.WholeStory
Selection.Copy
ActiveWindow.Close
Selection.Paste
End Sub
I am new to VBA and cannot figure out what is wrong with this code, that
would cause the macro to run most of the time but fail about 20%. Any
thoughts or solutions are appreciated... Tag: Sharing macro ind Word 2003 Tag: 61442
Macro could not be created.
Using Word 2002 SR3 and Windows XP Pro SP2: When I open up an existing
template and attempt to create a macro, I get the message "The macro could
not be created." Same result whether I use Tools|Macros|Create or go through
the VB Editor. When I attempt to copy a macro from another template, I get
the message "The macro could not be copied." Accessing the file from another
computer on the network yields same results. However, it appears that I can
create a macro using the normal template. Macro security is set at minimum,
and template is not protected. Tag: Sharing macro ind Word 2003 Tag: 61440
Changing language of textboxes
I regularly receive documents from French colleagues - The first job I have
to do is check their spelling. I have a macro that will select all the text
and tables and change their language setting to wdEnglishUK it will not,
however, cope with text boxes can anyone tell me (with code example please)
how to achieve this?
Many thanks in advance Tag: Sharing macro ind Word 2003 Tag: 61436
Clearing the clipboard in VBScript.
Hi all,
I am manipulating Word, using VBScript, and in the process, a large amount
of text is put in the clipboard. When the manipulation is finished, the
Word document is presented to the user. However, when the user closes word,
a prompt is displayed asking whether or not to discard the contents of the
clipboard.
How do I either clear the clipboard, or set a flag within Word, such that it
automatically discards the contents of the clipboard before on closure?
"Clipboard.Clear" appears to have no effect in VBScript.
Gem Tag: Sharing macro ind Word 2003 Tag: 61432
search a word document for words in a list
I need to check a Word document for words in a acronym list, then highlight
the words found in the acronym list.
This will allow me to use a generic acronym table in the document, then
remove all the unused terms in the Word Doc. Tag: Sharing macro ind Word 2003 Tag: 61431
Comments in word 2003 and changes
Hi,
I have a hard time using the "comments" feature in 2003 which I find
very confusing compared to the way Word 97 handles them.
I have created a macro that mimics the Insert Comments from Word 97
which works ok.
I am stumped trying to reproduce, even approximately, Word 97 feature
with regards to View Comments, which was straighforward. I find the
Markup feature particularly annoying. I wwould like to see the comments
in the View menu in a normal display and be able to delete them from
there, which presupposes that, as in Word 97, the corresponding initials
appear in a visible manner in the text.
Likewise with regards to accepting or refusing changes, the new
interface is much less convenient (IMHO). Any way the Word 97 behavior
could be mimicked?
Any help would be greatly appreciated.
--
John Doue Tag: Sharing macro ind Word 2003 Tag: 61430
My VB6 MS Word VBA code crashes Word - Word97
Hello
My Visual Basic application writes some text to a Word document. It usually
works but on two computers on a site it crashes my application.
Anyone got any ideas on where to start looking. Is removing Word, cleaning
up and re-installing the only option?
I am going on site to run the same VBA code from Excel to see if that works.
I can then check line for line what happens.
The basic code is here:
Private Sub cmdTestWord_Click()
Dim iSequence As Integer 'used to locate correct contact
Dim sDear As String 'Salutation on letter
Dim sTemp As String 'temp string to create address
Dim sLetter1 As String
Dim sLetter2 As String
Dim sLetter3 As String
Dim sSalute1 As String
Dim sSalute2 As String
Dim sSalute3 As String
Dim Title As String
Dim Firstname As String
Dim Initials As String
Dim Surname As String
Dim strPosition As String
Dim Familiar As String
Dim Ind As Integer
Dim ret As Long
Dim strToWord As String
'On Error GoTo WordErr
'Time bootup
'Dim dblSTime As Double
'dblSTime = Timer
'dblSTime = (Timer - dblSTime)
'MsgBox "Time taken: " & dblSTime
'Debug.Print "Time taken: " & dblSTime
Dim objWord As Word.Application
Dim objWordDoc As Word.Document '''''''''''''''''****
Dim docspath As String
'Time loading of Word
'Dim dblSTime As Double
'dblSTime = Timer '''''''''''''''''''''''''''
On Error Resume Next 'WordStart
LogError 0, "Just before Set objWord = GetObject(, Word.Application)",
"TestWord"
Set objWord = GetObject(, "Word.Application")
LogError 0, "After Set objWord = GetObject(, Word.Application)", "TestWord"
If Err.Number = 429 Then
Set objWord = New Word.Application '
CreateObject("Word.Application")
LogError 0, "After Set objWord = New Word.Application", "TestWord"
End If
If objWord Is Nothing Then
LogError Err.Number, "Unable to load Word object. Word is Nothing",
"Letter in frmContacts"
Exit Sub
End If
'' REMOVE THIS
objWord.Visible = True
LogError 0, "After objWord.Visible = True", "TestWord"
'On Error GoTo WordErr
Dim strLetter As String
strLetter = "letter.dot"
docspath = "C:\"
docspath = docspath & strLetter
If FileExists(docspath) = False Then
MsgBox "File: " & docspath & " does not exist check your document
template path and check that the selected template document exists"
Exit Sub
End If
Title = "Mr"
Firstname = "Angus"
Initials = "R"
Surname = "Comber"
Familiar = "Angus"
strPosition = "Director"
'sDear stuff
sDear = Familiar 'Dear
'Now need to address AddressLine
strToWord = Firstname & " " & Surname
strToWord = strToWord & VBA.Chr(13) & "5 Enmore Gardens"
strToWord = strToWord & VBA.Chr(13) & "East Sheen"
strToWord = strToWord & VBA.Chr(13) & "London, SW14 8RF"
LogError Err.Number, "Just before Set objWordDoc =
objWord.Documents.Add(docspath, False)", "TestWord"
Set objWordDoc = objWord.Documents.Add(docspath, False)
' Sometime get a valid objWord object but problem creating document based on
template.
' So still need to check a valid objWordDoc created
If objWordDoc Is Nothing Then
MsgBox "Unable to create Word Document object based on template: " &
docspath & " Unable to proceed with Word creation", vbCritical, "Word Error"
LogError Err.Number, "Unable to create objWordDoc object. 'Set
objWordDoc = objWord.Documents.Add(docspath, Fales)'", "Letter in
frmContacts"
objWord.Visible = True
Exit Sub
End If
objWord.Application.ScreenUpdating = False
'objWord.Visible = True
Dim bRet As Boolean
'Find <Address> & replace with strToWord
'objWord.Selection.Find.Execute findtext:="<Address>",
replacewith:=strToWord ', Replace:=wdReplaceAll
' Just in case named arguements can cause a problem - remove them!
'objWord.Selection.Find.Execute "<Address>", , , , , , , , , strToWord, True
'objWord.ActiveDocument.Range.WholeStory
'bRet = objWordDoc.Range.Find.Execute("<Address>", , , , , , , , ,
strToWord, Word.wdReplaceAll)
LogError 0, "Just before first LateBindingReplace objWordDoc, < Address >,
strToWord", "TestWord"
LateBindingReplace objWordDoc, "<Address>", strToWord
'Find <Dear> & replace with sDear
'objWord.Selection.WholeStory
'objWord.Selection.Find.Execute findtext:="<Dear>", replacewith:=sDear ',
Replace:=wdReplaceAll
'objWord.Selection.Find.Execute "<Dear>", , , , , , , , , sDear, True
'objWordDoc.Range.Find.Execute "<Dear>", False, False, , , , , , , sDear,
True
LateBindingReplace objWordDoc, "<Dear>", sDear
LogError 0, "After last LateBindingReplace objWordDoc, < Dear >, strToWord",
"TestWord"
'objWordDoc.Range.Find.Execute
'Find <Start> & place cursor for user to start typing
'objWord.Selection.WholeStory
'objWord.Selection.Find.Execute findtext:="<Start>", replacewith:="" ',
Replace:=wdReplaceAll
'objWordDoc.Range.WholeStory ' select all text
'objWordDoc.Range.Find.Execute "<Address>", False, False, False, False,
False, True, Word.wdFindContinue, False, "Abba", Word.wdReplaceAll
'If Err.Number <> 0 Then
' LateBindingReplace objWordDoc, "<Address>", strToWord
'End If
'objWordDoc.Range.Find.text = "<Address>"
'objWordDoc.Range.Find.Replacement.text = "Abba"
'objWordDoc.Range.Find.Execute
LogError 0, "Just before objWord.ActiveDocument.Variables(SiteID).Value =",
"TestWord"
objWord.ActiveDocument.Variables("SiteID").Value = 3
objWord.ActiveDocument.Variables("HType").Value = "Letter"
objWord.ActiveDocument.Variables("HComputer").Value = "MyComputername"
LogError 0, "After last objWord.ActiveDocument.Variables(HComputer).Value
=", "TestWord"
LogError 0, "Just before objWord.Application.ScreenUpdating = True",
"TestWord"
objWord.Application.ScreenUpdating = True
LogError 0, "Just after objWord.Application.ScreenUpdating = True",
"TestWord"
objWord.Visible = True
LogError 0, "Just after objWord.Visible = True", "TestWord"
objWord.Application.WindowState = Word.wdWindowStateMaximize
LogError 0, "Just after objWord.Application.WindowState = ", "TestWord"
LogError 0, "Just before bjWord.Application.Activate", "TestWord"
objWord.Application.Activate
LogError 0, "Just after bjWord.Application.Activate", "TestWord"
'dblSTime = (Timer - dblSTime)
'MsgBox "Time taken: " & dblSTime
End Sub
Public Sub LogError(ByVal errnum As Integer, ByVal ErrDescription As String,
Optional ByVal ProcName As String)
On Error Resume Next
Dim msg As String
Dim iFilenum As Integer 'To get a free filenumber
msg = Date & vbTab & Time & vbTab & ProcName & vbTab & errnum & vbTab &
ErrDescription
iFilenum = FreeFile
Open "C:\Errors.log" For Append As #iFilenum
'Write new value
Print #iFilenum, msg
Close #iFilenum
' MsgBox msg
'Debug.Print msg
End Sub
' Due to http://support.microsoft.com/default.aspx?scid=kb;EN-US;292744
' which is a COM problem with Word's Find object clashing with an old
version of Excel
' sometimes Find method will NOT work. So have to use Late binding to
accomplish
' Find replace. Requires a Word Document object plus search and replace
strings
Public Function LateBindingReplace(oWordDoc As Word.Document, strFind,
strReplace) As Long
On Error Resume Next
Dim oFind As Object ' Word.Find
'MsgBox "we are in latebindingreplace now!"
Set oFind = oWordDoc.Content.Find
If oFind Is Nothing Then
LogError Err.Number, "Unable to create oFind object. '",
"LateBindingReplace in modMisc"
LateBindingReplace = -1
Exit Function
End If
oFind.Execute strFind, False, False, False, _
False, False, True, Word.wdFindContinue, False, strReplace, _
Word.wdReplaceAll
LateBindingReplace = Err.Number
End Function
Private Function FileExists(strFile As String) As Boolean
Dim MyFile As String
' Returns filename if it exists.
MyFile = Dir(strFile)
If MyFile <> "" Then
FileExists = True
Else
FileExists = False
End If
End Function Tag: Sharing macro ind Word 2003 Tag: 61426
Hi.
What's the easiest way to share/distribute macros in Word 2003?