Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

WORD VBA QUESTION

Posted on 2001-06-17
11
Medium Priority
?
229 Views
Last Modified: 2008-03-06
The following code returns an error 4198 - which says that the document failed to close - I'm a little light headed and feeling silly tonite - so why the error ?

With ActiveDocument
  .SaveAs FileName:=szSavedFileName, FileFormat:=wdWordDocument, AddToRecentFiles:=False
  .Close
End With

KhrisE
0
Comment
Question by:KhrisE
11 Comments
 
LVL 1

Expert Comment

by:underground712
ID: 6199728
did you try
   Application.Quit
0
 
LVL 13

Expert Comment

by:cri
ID: 6200151
Most probably the document is a fresh one, i.e. never ever saved.

Sub TestSaveAs()
  Dim szSavedFileName As String
 
  szSavedFileName = "testsave.doc"
  With ActiveDocument
   .SaveAs FileName:=szSavedFileName, FileFormat:=wdWordDocument, AddToRecentFiles:=False
   .Close
  End With
End Sub

All other possible errors like invalid paths, unitialized filename, read-only attributes etc did not give a 4198.
0
 
LVL 13

Expert Comment

by:cri
ID: 6201194
Under Windows NT 4 SP5 the Office version (97 SR-2) runs your code nicely, if 'szSavedFileName' does not contain the path then the default/LastUsed directory is passed automatically. Will check whether Windows 98 SE really behaves differently.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:KhrisE
ID: 6201733
This is being run on WIN2000 Professional Edition (Desktop Version I think it is known as) using Office 97 - now I dont know if I ever installed service pack 2 - I'll check

>>Most probably the document is a fresh one, i.e. never ever saved.

Correct

I also tried your coding - same error - so I'll check the service pack

KhrisE
0
 
LVL 13

Expert Comment

by:cri
ID: 6201945
Try passing the intended filename with the path. Also check whether you have a default Document directory set in Tools|Options|FileLocations.
 
0
 
LVL 1

Author Comment

by:KhrisE
ID: 6201992
OK - I've found the error

szSavedFileName  is made up with a date and time string at the end of it formatted at follows :

szFileDateTime = Format(Now, "mm-dd-yyyy - hh:mm:ss")

when I changed ":" to :

szFileDateTime = Format(Now, "mm-dd-yyyy - hh-mm-ss")

the whole function worked fine

How can I include the time formated with ":" between the time parts - I have tried enclosing the whole string in double quotes and it does not work.

I cant understand this I had the same function working fine in VB but not in VBA ... ah



Many thanks in advance

KhrisE
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 150 total points
ID: 6202066
use the escape caracter (which is \ by default):

szFileDateTime = Format(Now, "mm-dd-yyyy - hh\:mm\:ss")

i suggest that you might also "escape" the rest:
szFileDateTime = Format(Now, "mm\-dd\-yyyy \- hh\:mm\:ss")

Cheers

0
 
LVL 1

Author Comment

by:KhrisE
ID: 6202116
OK - points go to each of Cri and AngelIII - Cri - collect your points as a question posted for you - I am alway greatful for the assistance and in this instance everyone mentioned helped greatly

KhrisE
0
 
LVL 13

Expert Comment

by:cri
ID: 6203998
KhrisE, I can not duplicate the error 4198 on my home PC. Therefore forget the "never ever saved". And, "my code" was only to show how I tested it, somehow it gave the 4198 error yesterday if inserted in a brand new document. Sorry to have mislead you. Therefore, I prefer you deleting the "points for", as, while I appreciate it, I do not feel having contributed to the solution.
0
 
LVL 1

Author Comment

by:KhrisE
ID: 6206024
you've contributed enough for me - perhaps you might answer something in a while when I have no points left - you honesty is exceptional - thanks

KhrisE
0
 
LVL 13

Expert Comment

by:cri
ID: 6243064
Save these points and you will have them to attract all Office experts instead relying on my memory. And, BTW, I did not even see this comment until called to 'attnchuunn' by amp.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
Lost Word File? Eagerly, need it back? Read ahead; this File Recovery guide is for you.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question