Solved

Problem saving the active document under a different name in Word with VBA

Posted on 2013-01-31
5
1,196 Views
Last Modified: 2013-02-01
Running VBA in Word (2010) under Windows 7, I have a VBA program that tries to save the active document under a different name than its current name. The active document can be a *.doc file or a *.docx file. We set the Boolean OldFormat to True if it is in the Word97 *.doc format. Otherwise the document has been generated with Word 2007 or later.
     Here is the code that is giving me problems:

     If OldFormat Then
            ActiveDocument.SaveAs2 FileName:=Path & TargetName, FileFormat:= _
                  wdFormatDocument, AddToRecentFiles:=True
      Else
            ActiveDocument.SaveAs2 FileName:=Path & TargetName, FileFormat:= _
                  wdFormatXMLDocumentMacroEnabled, AddToRecentFiles:=True
      End If

     With a *.doc file, OldFormat = TRUE, so if we step through the code above, control goes to the first of those two “ActiveDocument.SaveAs2” commands. This code works perfectly on my computer, but on another computer I get an error 438 message: “Object does not support this property or method” at that point. The Path appears to be correct, the TargetName is a valid filename, WdFormatDocument = 0.
     What could be causing the 438 error?

jra
0
Comment
Question by:JohnRobinAllen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 500 total points
ID: 38842036
I get that error on my computer if I use SaveAs2. That is because I only have Word 2007. To run under all releases from Word 97 onwards, use SaveAs.
0
 
LVL 59

Expert Comment

by:Chris Bottomley
ID: 38842628
Can you confirm if the other computer is also 2010 ... if it's 2007 then see Grahams comment.  If it is a 2010 install then it may be the path at fault.

Chris
0
 

Author Comment

by:JohnRobinAllen
ID: 38843773
I'll confirm that information after the other party is awake. I'm typing this at 7:30 a.m. in Priddis, Alberta (Mountain time) and he is in Seattle (Pacific Time, 6:30 a.m.), so it is too early to reach him now.
     I had the same results with another friend in Winnipeg (Central Standard Time, 8:30 a.m.), but I cannot contact him until others here are awake too.
          I strongly suspect that Graham Skan's solution will solve the problem and that the path is correct.
     There is another problem that I may pose in a separate question: the person in Seattle is having trouble reading a variable stored in the document, but I will save the details for later (not with this query). His computer reads the variable but then it fails a test in an "If" statement. If I cannot find out what is wrong with that, I'll give full details in another query.
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 38843837
JRA,
SaveAs2 accepts an extra argument - CompatibilityMode. If you don't need to use it, you can stick to the old SaveAs method.

It sounds interesting, but I have a feeling that you will be able to solve your Seattle contact's problem yourself.
0
 

Author Closing Comment

by:JohnRobinAllen
ID: 38845602
This is the solution. However G.S. supplies further useful information about the command in a message below.

Once again, many thanks to GS and to EE!
Appreciation also to CB. He could have found a cause of the problem but the problem lay elsewhere.

j.r.a.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Do you ever need to create a 20 page Word document for some testing purpose? Are you tired of copying & pasting old boring "lorem ipsum" text over and over again, increasing font size and line space in order to make the document 20+ pages long? Look…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
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 …
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.

756 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