Solved

WORD VBA QUESTION

Posted on 2001-06-17
11
216 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: dandraka
There are several quick shortcuts that can make your life easier in Microsoft Programs.  These simple tips and tricks will your work more productive and you faster at completing your tasks! MS Word (1) Creating Re-usable Scraps You can create s…
Outlook Free & Paid Tools
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

708 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