Consulting

Results 1 to 7 of 7

Thread: Corrupt Word Document after VBA Macros

  1. #1

    Corrupt Word Document after VBA Macros

    Hello,

    After using following code in my .docm file I can't open .docx file (see error below)

        Dim FolderPath As String
        Dim DocName As String
    
    
        DocName = TName & "" & RevName & " " & sCustomer & " " & Title_txt & " _ 5CU"
        FolderPath = Environ("HOMEDRIVE") & Environ("HOMEPATH") & "\Downloads" & "\" & DocName & ".docx"
    
    
        With ActiveDocument
            .Fields.Update
            .SaveAs FileName:=FolderPath
            MsgBox "Proposal Documents saved as <" & DocName & "> in your Downloads folder"
           ' .Close SaveChanges:=wdSaveChanges
        End With

    corrupt.png

  2. #2
    Is the document empty?
    Have you used the debugging tools to view the contents of the document before the save occurs?

  3. #3
    VBAX Expert Dave's Avatar
    Joined
    Mar 2005
    Posts
    855
    Location
    I think U need to use SaveAs2 when changing the file extension. HTH. Dave

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,768
    Location
    Is the "" supposed to be "<space>" ?

    DocName = TName & "" & RevName & " " & sCustomer & " " & Title_txt & " _ 5CU"
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    Banned VBAX Newbie
    Joined
    Aug 2024
    Posts
    2
    Location
    I suggest repairing the file, checking macro settings, converting the format, and temporarily disabling security software.
    Last edited by georgiboy; 08-21-2024 at 10:06 PM. Reason: Removed spam

  6. #6
    Hi all,

    Document is not empty, macro is pasting some text and values from excel to word.
    The thing is, when I SaveAs manually .docm to .docx (after macro run), it saves correctly and .docx opening without any trouble.
    When I use code from first message to auto save and the end of macro work, it gives me corrupt error.



    Quote Originally Posted by Dave View Post
    I think U need to use SaveAs2 when changing the file extension. HTH. Dave
    I tried SaveAs2 instead of SaveAs but corruption still remains.

    Quote Originally Posted by Paul_Hossler View Post
    Is the "" supposed to be "<space>" ?
    Yes, it is space.

  7. #7
    VBAX Contributor
    Joined
    Jul 2020
    Location
    Sun Prairie
    Posts
    124
    Location
    Why is this a .docm and not a .dotm?
    When a new document is created based on the template it can simply be saved as a docx file.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •