Solved

WORD VBA QUESTION

Posted on 2001-06-17
11
217 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction It seems that at least a couple of times per month, I answer a question that requires automating Outlook from another Microsoft Office application, usually (although not always) to send one or more email messages.  For example: …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now