Solved

WORD VBA QUESTION

Posted on 2001-06-17
11
218 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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 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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
OneDrive for Office 365 Users 2 64
TSQL DateADD update Question 4 41
Excel 2013 spreadsheet opens without custom margins 13 21
Formula help - MIN 7 17
Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

831 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