VBA - ActiveDocument.Save with WINXP Pro
Author |
Message |
Gary Bre #1 / 9
|
 VBA - ActiveDocument.Save with WINXP Pro
Good morning. Can anyone please shed any light on this problem I am having. We use a AC97 database to produce letters in Word 97 by automated mailmerge. The data is first merged to file.rtf which in turn becomes the data source for the word merge document file.doc. This has work OK for 6 years with Windows 98 but we have now upgraded to XP pro and I am having problems. On 3 of our 30 PCs the merge will not complete from the file.rtf to the file.doc and asks me if I want to send an error report to MS. If I then give the user another copy of the mdb and file.doc it works perfectly for 2-3 days before I have the problems again. The code below is the code of the macro within the normal.dot this file is based on and it stops at "ActiveDocument.Save" (3rd line from bottom). If anyone has any ideas why this messes up with XP and on only certain PCs plaese let me know. I have even taken the PC back to factory settings and reinstalled Office 97 with no joy. ..................................................................... Sub Letter ' ' Letter Macro ' Macro recorded 01/11/97 by Gary Brett ' Dim MyValue With ActiveDocument.MailMerge.DataSource .ActiveRecord = wdFirstRecord MyValue = .DataFields("Letter_ID").Value End With With ActiveDocument.MailMerge .Destination = wdSendToNewDocument .MailAsAttachment = False .MailAddressDieldName = "" .MailSubject = "" .SuppressBlankLines = True With .DataSource .FirstRecord = wdDefaultFirstRecord .LastRecord = wdDefaultLastRecord End With .Execute Pause:=True End With ChangeFileOpenDirectory "\\P200-3\C DRIVE\MSOFFICE\EMSL Letters\Archive Letters" ActiveDocument.SaveAs FileName:=MyValue, FileFormat:=wdFormatDocument, _ LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _ :="", ReadOnlyRecommended:=True, EmbedTrueTypeFonts:=False, _ SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _ False Selection.MoveDown Unit:=wdLine, Count:=7 Windows(2).Activate ActiveDocument.Save ActiveDocument.Close End Sub
|
Sun, 13 Nov 2005 21:03:23 GMT |
|
 |
Cindy Meister -WordMVP #2 / 9
|
 VBA - ActiveDocument.Save with WINXP Pro
Hi Gary, I'm a bit confused, here. Partly, it's that we're probably not using the same terminology for things. 1) You have an Acc97 mdb that exports data to an RTF file as a data source. OK... What's the file format? Tab-delimited, comma-delimited...? 2) The macro code is stored in what? A document? A template? Normal.dot? (There can be only ONE Normal.dot on a user's machine, so the statement "the code of the macro within the normal.dot this file is based on" is a bit confusing, for me combined with "file.doc") 3) And the main merge document is what? And where is it saved: locally, or on the network? All that said, perhaps you need to check the network connections and folder permissions for these few problem machines. If the crash is happening on "Save", I have the gut feeling saving the document may be damaging it, somehow. And this is most often caused by "hiccups" when it's being opened/saved (if the user or a macro isn't doing any editing). Quote: > We use a AC97 database to produce letters in Word 97 by > automated mailmerge. The data is first merged to file.rtf which in > turn becomes the data source for the word merge document file.doc. > This has work OK for 6 years with Windows 98 but we have now upgraded > to XP pro and I am having problems. On 3 of our 30 PCs the merge will > not complete from the file.rtf to the file.doc and asks me if I want > to send an error report to MS. If I then give the user another copy of > the mdb and file.doc it works perfectly for 2-3 days before I have the > problems again. The code below is the code of the macro within the > normal.dot this file is based on and it stops at "ActiveDocument.Save" > (3rd line from bottom). If anyone has any ideas why this messes up > with XP and on only certain PCs plaese let me know. I have even taken > the PC back to factory settings and reinstalled Office 97 with no joy. > ...................................................................... > Sub Letter > ' > ' Letter Macro > ' Macro recorded 01/11/97 by Gary Brett > ' > Dim MyValue > With ActiveDocument.MailMerge.DataSource > .ActiveRecord = wdFirstRecord > MyValue = .DataFields("Letter_ID").Value > End With > With ActiveDocument.MailMerge > .Destination = wdSendToNewDocument > .MailAsAttachment = False > .MailAddressDieldName = "" > .MailSubject = "" > .SuppressBlankLines = True > With .DataSource > .FirstRecord = wdDefaultFirstRecord > .LastRecord = wdDefaultLastRecord > End With > .Execute Pause:=True > End With > ChangeFileOpenDirectory "\\P200-3\C DRIVE\MSOFFICE\EMSL > Letters\Archive Letters" > ActiveDocument.SaveAs FileName:=MyValue, > FileFormat:=wdFormatDocument, _ > LockComments:=False, Password:="", AddToRecentFiles:=True, > WritePassword _ > :="", ReadOnlyRecommended:=True, EmbedTrueTypeFonts:=False, _ > SaveNativePictureFormat:=False, SaveFormsData:=False, > SaveAsAOCELetter:= _ > False > Selection.MoveDown Unit:=wdLine, Count:=7 > Windows(2).Activate > ActiveDocument.Save > ActiveDocument.Close > End Sub
Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003) http://www.mvps.org/word This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :-)
|
Wed, 16 Nov 2005 18:33:53 GMT |
|
 |
Gary Bre #3 / 9
|
 VBA - ActiveDocument.Save with WINXP Pro
Hi Cindy & thanx for your time & reply. 1] The line that exports the data is as follows: DoCmd.OutputTo acForm, "Letters", "RichTextFormat(*.rtf)", "C:\emsl\temp\Letters.rtf", False, "" 2] The macro code I posted before is stored in the "normal.dot" template and the user has only normal.dot on the XP machine. 3]The main merge document is called FFX.doc and is held locally in a folder called emsl. What should happen is that the FFX.doc opens up and takes its data from the Letters.rtf (as in step 1 above), then creating a copy which will be saved to a network folder for archiving. I know this is all controlled by the macro because if I select enable macros it does not work & I recieve the MS error message. However if I choose not to enable macros the document opens with the merged data but no copy is created for the archive. I only know that because the merged document is named in the title bar as eg:12345.doc as opposed to FFX.doc Hope this cleared the mess up a little and again thanx for your time G
Quote: > Hi Gary, > I'm a bit confused, here. Partly, it's that we're probably not using the > same terminology for things. > 1) You have an Acc97 mdb that exports data to an RTF file as a data > source. OK... What's the file format? Tab-delimited, comma-delimited...? > 2) The macro code is stored in what? A document? A template? Normal.dot? > (There can be only ONE Normal.dot on a user's machine, so the statement > "the code of the macro within the normal.dot this file is based on" is a > bit confusing, for me combined with "file.doc") > 3) And the main merge document is what? And where is it saved: locally, > or on the network? > All that said, perhaps you need to check the network connections and > folder permissions for these few problem machines. If the crash is > happening on "Save", I have the gut feeling saving the document may be > damaging it, somehow. And this is most often caused by "hiccups" when > it's being opened/saved (if the user or a macro isn't doing any > editing).
|
Sat, 19 Nov 2005 21:12:49 GMT |
|
 |
Cindy Meister -WordMVP #4 / 9
|
 VBA - ActiveDocument.Save with WINXP Pro
Hi Gary, Quote: > Hope this cleared the mess up a little
Mmm, not really... Quote: > I only know that because the > merged document is named in the title bar as eg:12345.doc as opposed > to FFX.doc
Above, the name in the title bar you're showing. Is this a name created by the macro? WHICH of the documents do you expect should be saved and closed by these lines from your original macro code: Windows(2).Activate ActiveDocument.Save ActiveDocument.Close The way I'm reading it, this would be the main merge document - not the result doc. Is there a REASON you'd want to save the main merge document? Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003) http://www.mvps.org/word This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :-)
|
Thu, 24 Nov 2005 20:20:01 GMT |
|
 |
Gary Bre #5 / 9
|
 VBA - ActiveDocument.Save with WINXP Pro
Hmmmm. Right. How can I explain myself better. The 12345.doc is an autonumber created in access to make the doc unique in the archive. This number is mereged to the rtf then the FFX.doc template. All the macro does I believe is save the merged doc to the archive which is a network drive... The FFX.doc should be closed without saving whilst the 12345.doc is left open and saved. Sorry to be vague on this...I have a feeling it is the way XP looks at filenames as this macro still operates fien with Win98 SE. Cheers G Quote: > Hi Gary, > > Hope this cleared the mess up a little > Mmm, not really... > > I only know that because the > > merged document is named in the title bar as eg:12345.doc as opposed > > to FFX.doc > Above, the name in the title bar you're showing. Is this a name > created by the macro? > WHICH of the documents do you expect should be saved and closed by > these lines from your original macro code: > Windows(2).Activate > ActiveDocument.Save > ActiveDocument.Close > The way I'm reading it, this would be the main merge document - not > the result doc. Is there a REASON you'd want to save the main merge > document? > Cindy Meister > INTER-Solutions, Switzerland > http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003) > http://www.mvps.org/word > This reply is posted in the Newsgroup; please post any follow question > or reply in the newsgroup and not by e-mail :-)
|
Sat, 26 Nov 2005 17:05:32 GMT |
|
 |
Cindy Meister -WordMVP #6 / 9
|
 VBA - ActiveDocument.Save with WINXP Pro
Hi Gary, Quote: > The 12345.doc is an > autonumber created in access to make the doc unique in the archive.
OK. I just wanted to make sure you weren't using that to indicate "Form Letter1" or something of that sort :-) Quote: > All the > macro does I believe is save the merged doc to the archive which is a > network drive... The FFX.doc should be closed without saving whilst > the 12345.doc is left open and saved.
Right. Then I suggest changing the macro like this, so that no mistakes can be made about which doc is meant in what situation. (Note: I'm doing this off the top of my head, so typos are possible!) Sub Letter ' ' Letter Macro ' Macro recorded 01/11/97 by Gary Brett ' Dim MyValue Dim doc as Word.Document Dim result as Word.Document Set doc = ActiveDocument With doc.MailMerge.DataSource .ActiveRecord = wdFirstRecord MyValue = .DataFields("Letter_ID").Value End With With doc.MailMerge .Destination = wdSendToNewDocument .MailAsAttachment = False .MailAddressDieldName = "" .MailSubject = "" .SuppressBlankLines = True With .DataSource .FirstRecord = wdDefaultFirstRecord .LastRecord = wdDefaultLastRecord End With .Execute Pause:=True End With Set result = ActiveDocument result.SaveAs FileName:="\\P200-3\C DRIVE\MSOFFICE\EMSL Letters\Archive Letters\" & MyValue, FileFormat:=wdFormatDocument, _ LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _ :="", ReadOnlyRecommended:=True, EmbedTrueTypeFonts:=False, _ SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _ False 'doc.Save doc.Close wdSaveChanges End Sub Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003) http://www.mvps.org/word This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :-)
|
Sat, 26 Nov 2005 23:54:09 GMT |
|
 |
Gary Bre #7 / 9
|
 VBA - ActiveDocument.Save with WINXP Pro
Hi Cindy.. I have tried to paste this is the module where I believe the code is breaking up but I must be thick cause it will not accept it.. The following code is red in color presumably meaning something is wrong: Set result = ActiveDocument result.SaveAs FileName:="\\P200-3\C DRIVE\MSOFFICE\EMSL Letters\Archive Letters\" & MyValue, FileFormat:=wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _ :="", ReadOnlyRecommended:=True, EmbedTrueTypeFonts:=False, _ SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _ False If you can asisst again I would be grateful as I realise you must have better things to do. I have tried all sorts of things like making sure the correct code is on the correct line but cannot seem to get rid of the code error.. Thanc again Gary Quote: > > The 12345.doc is an > > autonumber created in access to make the doc unique in the archive. > OK. I just wanted to make sure you weren't using that to indicate "Form > Letter1" or something of that sort :-) > > All the > > macro does I believe is save the merged doc to the archive which is a > > network drive... The FFX.doc should be closed without saving whilst > > the 12345.doc is left open and saved. > Right. Then I suggest changing the macro like this, so that no mistakes > can be made about which doc is meant in what situation. (Note: I'm > doing this off the top of my head, so typos are possible!) > Sub Letter > ' > ' Letter Macro > ' Macro recorded 01/11/97 by Gary Brett > ' > Dim MyValue > Dim doc as Word.Document > Dim result as Word.Document > Set doc = ActiveDocument > With doc.MailMerge.DataSource > .ActiveRecord = wdFirstRecord > MyValue = .DataFields("Letter_ID").Value > End With > With doc.MailMerge > .Destination = wdSendToNewDocument > .MailAsAttachment = False > .MailAddressDieldName = "" > .MailSubject = "" > .SuppressBlankLines = True > With .DataSource > .FirstRecord = wdDefaultFirstRecord > .LastRecord = wdDefaultLastRecord > End With > .Execute Pause:=True > End With > Set result = ActiveDocument > result.SaveAs FileName:="\\P200-3\C DRIVE\MSOFFICE\EMSL > Letters\Archive Letters\" & MyValue, > FileFormat:=wdFormatDocument, _ > LockComments:=False, Password:="", AddToRecentFiles:=True, > WritePassword _ > :="", ReadOnlyRecommended:=True, EmbedTrueTypeFonts:=False, _ > SaveNativePictureFormat:=False, SaveFormsData:=False, > SaveAsAOCELetter:= _ > False > 'doc.Save > doc.Close wdSaveChanges > End Sub > Cindy Meister > INTER-Solutions, Switzerland > http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003) > http://www.mvps.org/word > This reply is posted in the Newsgroup; please post any follow question > or reply in the newsgroup and not by e-mail :-)
|
Tue, 29 Nov 2005 17:53:57 GMT |
|
 |
Cindy Meister -WordMVP #8 / 9
|
 VBA - ActiveDocument.Save with WINXP Pro
Hi Gary, Quote: > I have tried to paste this is the module where I believe the code is > breaking up but I must be thick cause it will not accept it.. > The following code is red in color presumably meaning something is > wrong: > Set result = ActiveDocument result.SaveAs FileName:="\\P200-3\C
These should be on two different lines. Position the cursor before result.SaveAs then press ENTER Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003) http://www.mvps.org/word This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :-)
|
Wed, 30 Nov 2005 18:33:48 GMT |
|
 |
Gary Bre #9 / 9
|
 VBA - ActiveDocument.Save with WINXP Pro
Hi Cindy and again thanx. Have now used this code in the PCs concerned so will wait and see the results. As I have said before this error is only occurring on 3 PCs so we will see what happens. I will post back in a few days to let you know if it succeeded but I really appreciate your help with this. Is it not strange that the old code seems to work on some XP Pcs and all Win98 PCs. I am baffled with this, but hopefully your recoding will sort it out.. Thanx again Gary Quote: > > I have tried to paste this is the module where I believe the code is > > breaking up but I must be thick cause it will not accept it.. > > The following code is red in color presumably meaning something is > > wrong: > > Set result = ActiveDocument result.SaveAs FileName:="\\P200-3\C > These should be on two different lines. Position the cursor before > result.SaveAs > then press ENTER > Cindy Meister > INTER-Solutions, Switzerland > http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003) > http://www.mvps.org/word > This reply is posted in the Newsgroup; please post any follow question > or reply in the newsgroup and not by e-mail :-)
|
Fri, 02 Dec 2005 18:11:19 GMT |
|
|
|