none
Converting .doc to .docx RRS feed

  • Question

  • I have tried to programmatically  convert a .doc file to .docx using OLE saveas.  The parameter FileFormat=wdFormatDocumentDefault does result in a .docx file, but the resulting saved .docx when opened with Word 2010 still displays Compatibility Mode at the top of the screen and users must do the conversion manually. 

    Maybe I am missing another parameter besides the FileFormat=wdFormatDocumentDefault which does result in a .docx but still does not let Word 2010 recognize the file as 100% converted.

    My saveas code is:

        ActiveDocument.SaveAs FileName:="Testing save as.docx", FileFormat:= _
            wdFormatDocumentDefault, LockComments:=False, Password:="", AddToRecentFiles:=True, _
            WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
             SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
            False

    Anyone know if there is another parameter needed besides FileFormat=wdFormatDocumentDefault?

    Thanks in advance for any help on this,

    Mark

    Friday, November 2, 2012 3:07 PM

Answers

  • I think this did the trick.

    The sequence that seems to work is:

    • Open the .doc file
    • SaveAs2 to a new .docx file
    • Open the new .docx file
    • Run this method on this .docx file and saveas2

    This method cannot be run on a .doc file because it generates an error that "the value used does not apply to this file format".  Essentially, this method seems to be meant to run only on a .docx file.

    In my research, I found that there are 2 .docx formats, one for 2007 and one for 2010.  It appears the initial saveas2, even tho I specified wd2010, was saved in 2007 format generating Compatibility Mode.  This method then converted that to 2010 and no more Compatibility Mode when the file is opened with word 2010.

    Thanks for your help on this.  If anyone finds an easier way than using 2 saves I hope they will post it.

    Mark

    Thursday, November 8, 2012 3:22 PM

All replies

  • Is the version of Word where your code is running Word 2010?

    Have you tried wdFormatXMLDocument ?


    Cindy Meister, VSTO/Word MVP, my blog

    Friday, November 2, 2012 3:48 PM
    Moderator
  • Tried wdFormatXMLDocument instead of wdFormatDocumentDefault .  A .docx file is saved, but when Word 2010 opens that file, Compatibility Mode is still displayed.  User must click on File and do a manual conversion, after which the file opens without Compatibility Mode being displayed.

    I must be missing something else, unless saveas cannot convert a .doc 100% to a .docx. 

    Appreciate any ideas on this,

    Mark

    Friday, November 2, 2012 4:56 PM
  • Oh, yes am using Word 2010 to run the code.

    Mark

    Friday, November 2, 2012 4:57 PM
  • See whether this post helps:Convert Doc to Docx and Docx to Doc


    Monday, November 5, 2012 7:33 AM
  • Hi Markus701,

    Thank you for posting in the MSDN Forum.

    Please follow the steps below:

    • Open the Registry Editor in Windows (Windows -> Run -> RegEdit) .
    • Search for the following key in the registry (use Ctrl + F): HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Word\Options
    • Take a screenshot of the values in right panel and upload it.

    This might be helpful for troubleshooting.

    Besides, you can check whether the solution on this page can help you or not.

    I look forward to your reply.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, November 5, 2012 9:33 AM
    Moderator
  • This looks like it could be helpful, but not really skilled in using .net or c# code. The article also referred to another article which discussed using wordconvert.exe from the office compatibility pack from MS. 

    I downloaded this and tried it without any success running from command prompt.  Did a google search on wordconvert.exe and found lots of others cannot get this to work either.

    Anyone checking in here -- any ideas on how to use wordconvert.exe successfully would be very much appreciated.  Anyone having any success using it for doc-docx conversions?

    Many thanks for any ideas on this,

    Mark

    Tuesday, November 6, 2012 12:59 AM
  • Hi Markus701,

    Thank you for your last reply.

    By asking you to follow those steps in my last reply, I want to check whether or not your registry keys have been changed. I've seen from this page that the change in registry key can cause Word been opened in compatibility mode by default.

    You can check that and let me know the result.

    Hope it helps.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, November 6, 2012 4:48 AM
    Moderator
  • Hi Markus

    If this is Word 2010 then try ActiveDocument.SaveAs2. This provides an additional parameter (the last one) that lets you set the Compatibility Mode:

     ActiveDocument.SaveAs FileName:="Testing save as.docx", FileFormat:= _
            wdFormatDocumentDefault, LockComments:=False, Password:="", AddToRecentFiles:=True, _
            WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
             SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
            False, CompatibiliyMode:=wdCurrent 'or wdWord2010


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, November 6, 2012 9:11 AM
    Moderator
  • Used regedit to locate the info you suggested.  Using the search string you recommended, regedit located the image uploaded.  Note the path at bottom of the attached image for the path regedit found.

    Thanks for you input on this,

    Mark

    Tuesday, November 6, 2012 6:53 PM
  • Thanks for your help on this.  Unfortunately, I tried SaveAs2 first with wdcurrent, then with wd2010.  In both cases the resulting saved .docx file when opened by word 2010 had Compatability Mode at the top of the screen.

    Saving this file as a .docx and reopening it caused the Compatability Mode to no longer be displayed.

    There must still be a setting I am missing to get the file to convert to be 100% docx format.  Any and all additional ideas you have would be most appreciated.

    Thanks,

    Mark

    Tuesday, November 6, 2012 7:12 PM
  • BTW, I should mention that I am working with a new laptop that has Office 2010 delivered from the factory, so this is not a updgrade of a previous version of Office.  Also, no modifications were made to the factory delivered configuration.

    I mention this because I saw some posts on the Web that remnants from a previouse version of Office on the same machine can sometimes cause the compatibility mode to display when it should not.

    Thanks,

    Mark

    Tuesday, November 6, 2012 7:23 PM
  • Hi Markus701,

    Sorry to cause you trouble, I should have been more clear. Since you're using Office 2010, please check the keys under 14.0.

    HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Word\Options

    I look forward to your reply.

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, November 7, 2012 2:16 AM
    Moderator
  • Hi Mark

    This isn't something I've ever had occasion to try, but looking through the object model I do find a Document.SetCompatibilityMode property. You might try setting that before doing save As and see if that helps? (And, if it does, I'd be very grateful if you'd report back)


    Cindy Meister, VSTO/Word MVP, my blog

    Wednesday, November 7, 2012 4:26 PM
    Moderator
  • I think this did the trick.

    The sequence that seems to work is:

    • Open the .doc file
    • SaveAs2 to a new .docx file
    • Open the new .docx file
    • Run this method on this .docx file and saveas2

    This method cannot be run on a .doc file because it generates an error that "the value used does not apply to this file format".  Essentially, this method seems to be meant to run only on a .docx file.

    In my research, I found that there are 2 .docx formats, one for 2007 and one for 2010.  It appears the initial saveas2, even tho I specified wd2010, was saved in 2007 format generating Compatibility Mode.  This method then converted that to 2010 and no more Compatibility Mode when the file is opened with word 2010.

    Thanks for your help on this.  If anyone finds an easier way than using 2 saves I hope they will post it.

    Mark

    Thursday, November 8, 2012 3:22 PM
  • I'm not sure that I understand the issue, but I have a Process Batch File addin and one of the processes is to convert files.  Here is the function that I use.  I think ".Convert" is what you are needing.

    Function Convert_Docs(ByRef Doc As Word.Document, ByRef bMaintainCompatibility As Boolean) As String
    Dim pDocName As String
    Dim i As Long
      On Error GoTo Err_Handler
      pDocName = ActiveDocument.FullName
      i = InStrRev(pDocName, ".")
      pDocName = Left(pDocName, i - 1)
      ActiveDocument.SaveAs FileName:=pDocName, FileFormat:= _
          wdFormatXMLDocument, AddToRecentFiles:=False
      If Not bMaintainCompatibility Then
        ActiveDocument.Convert
      End If
      Convert_Docs = Doc.Name & " processed successfully."
    Err_ReEntry:
      Exit Function
    Err_Handler:
      Convert_Docs = Doc.Name & " failed to process.  Error summary: " & Err.Description & "."
      Resume Err_ReEntry
    End Function

    Here is a link to the addin:  http://gregmaxey.mvps.org/word_tip_pages/process_batch_folder_addin.html


    Greg Maxey Please visit my website at: http://gregmaxey.mvps.org/word_tips.htm

    Thursday, November 8, 2012 11:03 PM
  • See whether this post helps:Convert Doc to Docx and Docx to Doc

    Hi emma, unfortunately the link is broken, can you correct it.

    I'm wondering does that blog describe a way to a file conversion without word interop in .NET?

    If yes please contact me, now I'm using the code from this article to convert DOC in .NET.

    Thanks in advance.

    Thursday, January 9, 2014 9:02 AM