Help with runtime error 438 - caused by using Office 2010 macro in Office 2007?

Hi,

I am trying to run a visual basic macro in excel 2007 that was created in excel 2010.

When working, the macro creates a word document, populates it with data in the spreadsheet then converts to a pdf before emailing.

I'm getting a 438 error at the point where it creates the word document.  I believe this is down to the different version of word I am using (having made some changes to the references in excel (to version 12.0).

The debugger has highlighted the following code as the issue:

objword.ActiveDocument.SaveAs2 Filename:=name & "_" & BookingID & ".docx", FileFormat:= _
wdFormatXMLDocument, LockComments:=False, Password:="", AddToRecentFiles _
:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts _
:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False, CompatibilityMode:=14

Running Office 2007 on a Windows 8.1 device.  Both 32-bit.

The code works perfectly on Office 2010 on a Windows 7 machine, both 64-bit.

I don't know how to code at all so any advice welcomed.

Thank you.

Answer
Answer

If you want full compatibility on the method use SaveAs, do not use SaveAs2. Also eliminate all of the properties other than Filename and FileFormat because for what you have shown, you are using the default settings anyway. And as Greg has pointed out, eliminate the Compatibility property.

With those changes your command is compatible on Office 2007, 2010, 2013 and even Office 2011 on the Mac.

________________________________
Richard V. Michaels
info@greatcirclelearning.com
Provides AuthorTec add-ins for Mac & Win-Office. Site: greatcirclelearning.com

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Answer
Answer
ADDENDUM...

After running windows update, this solved the problem.

Thank you again.

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 5, 2021 Views 2,980 Applies to: