Word 2007 VBA vs Word 2010 VBA - Macro Failure

Hi,
I have a macro that when run in Word 2007 VBA works fine (Takes a Word Template, an Excel Spreadsheet and produces PDF output of merged documents).
Sub mergethem_be() '
' merge1record_at_a_time Macro
Dim fd As FileDialog
'Create a FileDialog object as a Folder Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
'Use the Show method to display the Folder Picker dialog box and return the user's action.
'The user pressed the button.
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
'vrtSelectedItem is aString that contains the path of each selected item.
'You can use any file I/O functions that you want to work with this path.
'This example displays the path in a message box.
SelectedPath = vrtSelectedItem
Next vrtSelectedItem
Else
MsgBox ("No Directory Selected. Exiting")
Exit Sub
End If
End With
'Set the object variable to Nothing.
Set fd = Nothing
Application.ScreenUpdating = False
MainDoc = ActiveDocument.Name
ChangeFileOpenDirectory SelectedPath
For i = 1 To ActiveDocument.MailMerge.DataSource.RecordCount
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.SuppressBlankLines = True
With .DataSource
.FirstRecord = i
.LastRecord = i
.ActiveRecord = i
docName = .DataFields("naam_mailing").Value & ".pdf"
End With
.Execute Pause:=False
Application.ScreenUpdating = False
End With
ActiveDocument.ExportAsFixedFormat OutputFileName:=docName, ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, From:=1, To:=1, Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, BitmapMissingFonts:=True, UseISO19005_1:=False
ActiveDocument.Close SaveChanges:=False
Next i
Application.ScreenUpdating = True
End Sub
If there are 31 rows in the spreadsheet it produces 31 PDF documents named based on the Name field in the Mail Merge Template.
However when I use the same Macro code in Word 2010, same mail merge template and same source excel, it produces the first PDF and then generates an error on the bolded line as if there was no longer a document available.
Now I know I use ActiveDocument.Close before going through the loop again, but that seems fine for Word 2007.
Am I missing something really obvious here?

If Bernie's ideas don't work, single step thru the code. Does the first file get created properly?
What is the error? If the file isn't created, then the ActiveDocument refers to the template which isn't good to close!
I suspect there is a different behavior in how Word 2010 works and your VBA code probably needs to reflect that, though VBA is usually very good at providing backwards compatibility.
Rod Gill
Author of the one and only Project VBA Book
www.project-systems.co.nz

Similar Messages

  • Opening Word 2007 docs in Word 2013 and formatting is changed??

    We just installed 2 new PC's on the network with Office 2013.  Everyone else is running 2007.  When an existing file is opened on either of the 2 PC's running Word 2013 the formatting and layout is changed.  The font is changed even though
    the same font is available and the layout is changed a little and the document does not fit on 1 page any more.  It shifts about 2 or 3 lines at the bottom to the next page.  When we open the same file in Word 2007 everything is still good.  Word
    2013 opens the file in 'compatibility mode' but still the layout is changed.  We have hundreds of documents that we need to be able to open in both Word 2007 and 2013.  Any suggestions on how we can make this work??

    Hi,
    As far as I know, if we open a Word 2007 file in Word 2013 with Compatibility Mode, it will preserve the layout of the document. I recommend you try to convert the document to the Word 2013 mode to test. Steps:
    Click the File tab.
    To convert the document without saving a copy, click Info, and then click
    Convert.
    Reference:https://support.office.com/en-us/article/Use-Word-2013-to-open-documents-created-in-earlier-versions-of-Word-609bbdba-96f2-407b-baaf-d8e53d60d34f?ui=en-US&rs=en-US&ad=US
    If this issue still exists, could you send us a sample file via Email ([email protected])? I'd like to test it.
    Regards,
    George Zhao
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • WORD 2010 Crashes Opening Word 2007 files

    WORD 2010 crashes when opening Word 2007 files. If you save the files in Office 2007 as an RTF file, then open in WORD 2010 and save as a DOCX it works fine. Why can't WORD open legacy documents (these are not big files ~13 pages).
    I have tried opening in safe mode, same effect - the doc opens and appears in the WORD window, and then the pop-up appears before you can do anything telling you that WORD 2010 has crashed.

    Try using Open and Repair on the problem docs.
    In the Open dialog, select the file, then click the arrow beside Open and choose Open and Repair
    If that doesnt help you may want to check  the How to troubleshoot damaged documents in Word 2007 and in Word 2010
    http://support.microsoft.com/kb/918429
    Regards, ~G MCSE, MCDST, MCITP, MCTS, MCP, CCNA

  • Equations in Word 2007 turns into horizontal lines

    This is something that has come up a lot lately. Documents written in Word 2007 which contains graphics such as equations get messed up when converting the documents to PDF. Instead of the equations, we only get horizontal lines.
    I've found several things that affect this behaviour:
    - It only happens in Windows XP
    - Word 2007, haven't tried 2010 yet
    - Acrobat 9.0 and Acrobat X
    It doesn't happen when printing to PDF, only via the Acrobat ribbon and via Save as Adobe PDF.
    I thought Acrobat X fixed this but it doesn't. Just upgraded. Any light on this?

    I have this problem, too. I am running Win XP, Office 2007, and Acrobat Pro 9.something.
    There is a detailed discussion of this here:
    http://acrobatusers.com/forum/pdf-creation/problem-converting-word-2007-equations
    They think it's a bug in a Microsoft patch. They offer a coupole of workarounds including printing to a PDF printer and saving the document as .doc.

  • RoboHelp for Word cannot open Word with Word 2007

    Thanks for your leignancy, I'm having trouble even starting
    to work with RoboHelp. I think I need detailed explanations. I did
    spend hours sifting through Robohelp's Help and this Forum, I'm
    stuck.
    I am trying to use
    RoboHelp for Word 7.0 , build 001, with Word 2007 on Vista.
    I need to work on help projects created with a previous
    version of RoboHelp.
    For some reason, when I open RoboHelp, the .doc file opens in
    Word next to it, but then RoboHelp freezes for several minutes,
    then I get a dialog box that says
    "RoboHelp" could not open Word .
    Then anytime I try to modify a topic in my help file, I get
    the same stall and error message, and my Word document stays stuck
    at the beginning on my first topic.
    Also, in Word,
    all Robohelp options don't work. I can't search for a topic
    for instance to locate it and modify it. When I click on search for
    a topic from the menu on top, nothing happens at all. If I click on
    search a topic from the right-click menu, then I get a message that
    because of security or confidentiality settings, the
    Macros don't work.
    I tried re-activating all Macros in Word 2007 Options, I
    closed everything, even re-booted the computer, but to no avail.
    Also, I tried saving my .doc into a .docx (Word 2007 format)
    to see if the Macros would be compatible then, but I got the exact
    same results.
    Right now, RoboHelp and Word don't seem to be "talking" to
    each other right, and the Macros don't work.
    Plus: I tried to test a modification I made in the .doc file
    by generating the WebHelp, but that didn't work either, I got an
    error message saying that the file couldn't be opened, but the path
    to the file was all wrong, with folder names I don't even have on
    my computer.
    If someone could figure this one out for me, I'd be very
    thankful, I'm the kind of person who likes something to work in a
    simple, linear way, 1-2-3... This is totally confusing for me right
    now.

    Ok, isn't that what I did when I re-activated the Macros in
    Word 2007?
    Word Options / security - confidentiality center / Parameters
    Activate all Macros (the lowest one on the list)
    Did that already. Also, I made backups of my projects, and
    tried with a new "brew" just in case I had messed it up along the
    way somewhere.
    First thing I did when I opened it again was change the
    output to WebHelp instead of WinHelp 4, since I can't open that in
    Vista anymore.
    I can generate the help in that format, but either way I try
    to make any modification it's not taken into account when I
    generate it.
    Example:
    In the french help project which I'm working on, I had a
    tittle that was miss-spelled.
    I tried modifying in in the Word .doc document, then generate
    the help, but the title was still wrong.
    So I tried changing in directly in Robohelp with the topic's
    properties.
    When I clicked OK, it stalled forever again, and then it said
    it couldn't take the modifications into account.
    And any text I cut and paste or changed in the .doc on Word
    remains unchanged in the WebHelp....
    Right now, the more I try, the more I'm stuck and the more
    questions I get. I'm seriously thinking I'd need some live
    coaching, on a chat or something, to get me started on the right
    track. Is there anyone who can do that? I'm so awfully stuck right
    now. And I feel like I'd unfurl a tsunami of ridiculous questions
    if I posted them all on the Forum now...
    *EXTRA*
    I did all the updates (7.0.3) and right now I'm re-installing
    everything.
    Arghhh.
    I missed one of the last days of ski this season, spent my
    whole week-end with this.
    I'm trying to sound rational and calm, but I'm actually so
    tired and exasperated, I'd have jumped through the window already
    if we weren't on the first floor... Still stuck at Step 1...
    What am I missing??

  • Word 2007 AddIn Cannot Run on Windows XP SP3 + Office 2007

    Hi All,
    I faced an issue regarding our Word 2007 AddIn cannot run on Office 2007 + WinXP SP3.
    I developed a Word 2007 AddIn using VS 2010. The addin works fine on Win7 + Office 2007. But It cannot run in Word 2007 in WinXP.
    I have tried the following testing.
    1. I rebuild a new WinXP environment + Office 2007 + VS 2010. No antivirus in my machine. I create the Word 2007 AddIn using VS 2010. But unfortunately, it cannot run in my WinXP machine. it's very strange.
    2. I rebuild a new Win7 environment + Office 2007 + VS 2010. No antivirus in my machine, and the same steps with previous. it runs fine.
    3. I noticed that, if I debug the Word AddIn Project using VS 2010 In XP, it cannot run into debug mode. I checked the Word Options
    I have highlight the test addins it always uncheck. If I checked it, when I reopen Word. it will change to uncheck status. 
    And the addins always in Inactive Application Addin group.
    @All guys, How to solve this issue? It's very very strange. 
    Thanks a lot for your help.
    Regards,

    Hello Ricky,
    First of all, I'd suggest checking the Trust Center settings in Outlook. Then take a look at the Disabled Items list. Is your add-in listed there?
    Microsoft Office applications can disable add-ins that behave unexpectedly. If an application does not load your add-in when you try to debug it, the application might have hard disabled or soft disabled your add-in.
    Hard disabling can occur when an add-in causes the application to close unexpectedly. It might also occur on your development computer if you stop the debugger while the Startup event
    handler in your add-in is executing.
    Soft disabling can occur when an add-in produces an error that does not cause the application to unexpectedly close. For example, an application might soft disable an add-in if it throws an unhandled exception while the Startup event
    handler is executing.
    When you re-enable a soft-disabled add-in, the application immediately attempts to load the add-in. If the problem that initially caused the application to soft disable the add-in has not been fixed, the application will soft disable the add-in
    again.
    You can read more about that in the
    How to: Re-enable an Add-in That Has Been Disabled article in MSDN.

  • Cannot enable acrobat 8.1.3 addin in Word 2007

    Hi,
    I cannot enable acrobat 8.1.3 addin in Word 2007.  In Word 2007 I go to the top left circle, word options, Add-Ins, Disabled Application Add-ins,  Acrobat PDFMaker Office COM Addin, and then "Go".
    I then see Acrobat PDFMaker Office COM Addin is unchecked.  When I check it, it notes that "This add-in is installed for all users on this computer, and can only be connected or disconnected by an administrator".  See attached jpg for details.  Please advise.
    Thanks,
    Joe

    As the instructions indicate, log in as the administrator and activate the option. If you do not have access to the administrator account, then ask your IT folks to do it for you.

  • Pdf 7 covert to Word 2007

    I am having a problem when I am using PDF 7 save as a word document. I am using Word 2007. The word will break at the end in every line. Please refer to image the below. How can I fix the problem? Thanks.

    I would make sure that you choose the Adobe Distiller Printer instance as the printer, before creating the pdf file. The problem you are seeing may be due to the need of Word to reformat each document according to the printer it thinks is being used to print the document.

  • DreamweaverCtrls.dll changed to MS Word 2007 icon

    I have installed CS3 but the DreamweaverCtrls.dll is not working well (tables do not pull through in datasets). After a long investigation, I just found out that the dll control has taken on the image if MS Word. Could this be the cause of my problem? How can I change it back to the usual .dll icon?.

    Another thing is I can print anything off the net (I just print several disney coloring pages for my nephew), I could also print a test page, but for some reason ms word 2007 and the word pad is printing blanks or doing the things I've listed above. I tried going to http://support.microsoft.com/ph/11377, concerning this but they don't seem to have a forum, they only have an index page for known issues of ms word 2007, but not a thing concerning my problems.

  • VBA help file in Word 2007 won't open

    When trying to open the VBA help in Word 2007 the following message occurs:"This webpage might not be displayed properly.  The content of the webpage does not match the type specified by the server.  Click here for options..."  After clicking,
    I get a popup which gives me the option to run or save "MS.winword.12.1033".  WHy doesn't the help just open?

    Hi Steph99,
    In addition to the reply from Paul
    P Clement IV
    above, the other Microsoft areas relating to
    WORD in Office you could try asking in are;
    http://social.technet.microsoft.com/Forums/en/word/threads
    and
    http://answers.microsoft.com/en-us/office/forum/word
    Regards,
    Click this link to see the NEW way of how to insert a picture into a forum post.
    Installing VB6 on Windows 7
    App Hub for Windows Phone & XBOX 360 developers.

  • Remove SaveAs prompt for Word 2007 VBA SaveAs in 64-bit Window 2008

    We use VBA WordApp_DocumentBeforeClose(ByVal Doc As Document, Cancel As Boolean)
    to save the word file to another name when user closes the file  .
    We use SaveAs to implement this like this:
     Doc.SaveAs FileName:=lcMetaFileName,  AddToRecentFiles:=False
    The lcMetaFileName is a file ame with full path.
    This SaveAs works fine with word 2003 and with word 2007 in Wndow 2008 32-bit.
    But with word 2007 in Wndow 2008 64-bit,every time this SaveAs is called ,
    a saveas prompt will be showed up asking for file ame , type,etc.
    We tried  adding 
       fileFormat:=wdFormatDocument97
    in the SaveAs call and adding
    Doc.Application.DisplayAlerts=wdAlertsNone
    and checked 'allow back ground save' in the word setting
    and we still get the prompt.
    How can we get rid of the prompt?

    Same here. My program uses demographics to create a filename and filetye as RTF, but it is ignored and a prompt pops up !!!! Frustating :(
    OS - Win 8.1 64 bit
    Office 365 32 bit (Word 2013)
    Same code works for all other versions

  • Word 2007 & Acrobat 9: Macro to generate PDF

    I'm trying to create a Word 2007 macro which does some checks on a document (for example, refreshes all fields and checks for broken x-refs by searching for the text "Error!") before PDFing it.
    Does anyone know what Microsoft VBA will perform the same task performed by clicking the  Acrobat-->Create PDF option?
    Also, if anyone know of any similar macros that perform error-checking on Word document, please let me know,
    Thanks,
    P.

    Footnotes in tables were the problem with my doc as well.  I tried the option of saving the doc as a Word 2003 file, but it didn't help.  I chatted with Adobe Customer Service and was provided this fix:
    In Word 2007, click on the Acrobat ribbon
    In the "Create Adobe PDF" panel, click on "Preferences"
    In the "Settings" tab, under "Application Settings," UNCHECK the box next to "Enable Accessibility and Reflow with tagged Adobe PDF"
    After that, I was able to create the PDF, and the table of contents and external hyperlinks all worked.  The footnotes were no longer hyperlinked, but since they're on the same page as the items they're referencing, that's not really a problem.  Cheers,
    JG

  • Detecting file type in vba for word

    I have directories full of files on a Mac.  Most of these files are Doc files, some Txt files and some other types. Unfortunately the files don't have file extensions (not hidden but actually no file extensions).  On a PC in a macro I need to open
    these  doc files (from the Mac) and do some manipulations on the files and then save them.  I have a macro which works as long as all the files are Doc files so if I can detect the file type in my macro I can skip the non-Doc files and process only
    the Doc files.
    Is there a way in a vba for word macro to detect a file type other than by the file extension?  Or if that can't be done can I put error trapping on my Open statement that will catch an attempt to Open a non-Doc type file?
    Thanks
    Harry Spier

    If your code is running on Windows and you are in a position to install software on it, you
    may be able to get reasonably reliable detection using dsofile.dll, which you can get here:
    I really do not know whether it will work with files stored or create on Mac (and in any case, if these are old Mac .doc files, you may find that Windows Word cannot open them anyway.
    You need to
     - register the dll via regsvr32
     - in VBE, use Tools->References... to make a reference to"DSO OLE Document Properties Reader 2.1"
     - use code such as the sample below. 
    Option Explicit
    Function IsWordDoc(FullName As String) As Boolean
    ' FullName is the full path name of the file you want to check
    Dim objDocumentProperties As DSOFile.OleDocumentProperties
    IsWordDoc = False
    Set objDocumentProperties = New DSOFile.OleDocumentProperties
    ' or you can add dsoOptionOnlyOpenOLEFiles to the options and
    ' use error trapping to detect -2147217148
    objDocumentProperties.Open sFileName:=FullName, ReadOnly:=True, Options:=dsoOptionDontAutoCreate
    If objDocumentProperties.IsOleFile Then
    If objDocumentProperties.OleDocumentFormat = "MSWordDoc" Then
    IsWordDoc = True
    End If
    End If
    objDocumentProperties.Close savebeforeclose:=False
    Set objDocumentProperties = Nothing
    End Function
    Sub testIsWordDoc()
    Debug.Print IsWordDoc("c:\a\test.doc")
    Debug.Print IsWordDoc("c:\a\test.xls")
    End Sub
    You may also find that the value of the property I am checking varies and that you need to look at other things, such as 
    objDocumentProperties.SummaryProperties.ApplicationName
    but that value definitely varies according to the version of Word used to create the .doc, so you would need to discover what values it can have in a valid .doc.
    Peter Jamieson

  • Word Templates for Microsoft Word 2007 or 2010

    Hello, gurus!!
    In Records Management I have documentation of how to create Fill-ins in Word 2003 for document templates, but in Word 2007-2010 its totally diferent.
    Does anyone have documentation or know how to make templates with Word 2007???
    also wich service pack for word should I use???
    Thanks!!!

    Hi Salvador,
    Perhaps the following note link may assist ...
    https://service.sap.com/sap/support/notes/1237688
    Br, Derrick

  • AA9 & Word 2007: Creating PDF disables macros

    I'm using Word 2007 with Adobe Acrobat Pro 9 and am getting a strange error. If I open a document, I can access the macros fine (I have the directory where the document template is located as my "Workgroup Templates setting).
    However, after I create a PDF of the document, I immediately get an dialog box saying "The macros in this project are disabled". When I try to access macros, I can't. Closing and opening the doc is a workaround but I'd like to know how to get rid of the problem.
    Regards,
    P.

    General Acrobat Problem Steps
    If you are having problems creating a PDF, there are two steps you should do FIRST
    Go to the appropriate vendor web site and apply all updates to the program you are using (several recent messages have concerned problems with MS Office conversion, with the response that different versions of Office have different BUGS that must be fixed by a download from Microsoft - and MS Office products are not the only ones which may, from time to time, need to be updated to work properly)
    Apply all updates IN NUMBER ORDER
    Acrobat Update http://www.adobe.com/support/downloads/product.jsp?product=1&platform=Windows
    Or, use the Microsoft product for Office 2007
    http://www.microsoft.com/downloads/details.aspx?FamilyId=4D951911-3E7E-4AE6-B059-A2E79ED87 041&displaylang=en

Maybe you are looking for

  • BO 4.1 SP3 "Database Middleware Selection" - drivers missing

    Hello guys, I've looked up my problem and I saw 2-3 similar scenarios, but couldn't get any good answer from previous discussions, so I'm asking again. I have a BI Platform, 4.1 SP3. BO Server is installed on WIN 2008 R2. Client Tools machine is on W

  • Function module to get the chars and key figures of an infocube

    Hi Everyone, Can anyone please let me know is there any function module where if I pass the infocube name as the input parameter, it has to give me the output parameters its characteristics and key figures. I require this to display the report in dri

  • Problems importing footage with Canon GL-2

    I'm brand new to Mac & FCP, migrating from Casablanca after 8+ years. I've had no luck using the "Capture Batch" option, so I've reverted to "Capture Now"...after reading lots of issues with the gl2. "Capture Now", though very time consuming, seems t

  • Using the if-modified since http header

    I've a few questions regarding this header. 1/ What is the point in using this header? Does it help with page ranking/hits? 2/ Is if useful for static html pages or just for dynamic ones? 3/ If it is useful for static pages, how do you add it? I.e ex

  • Does iTunes check in any way to be sure a download is clean?

    I've purchased a few TV shows with 'glitches' (random static or pixelizations), though none of them have lasted more than a second or two. I know that iTunes allows only one download of each purchase. Given that, I would have thought that it would do