ms word - VBA script convert folder of .rtf files to .docx files - two minor problems -


i use vba script (see below) in word 2013 convert folder of .rtf files .docx files. works, has 2 minor problems.

  1. i have acknowledge each original file .rtf file. when word opens each .rtf file there's dialog requires me confirm each file .rtf file.
  2. when view converted .docx files in word there's "compatibility mode" header, suggests haven't converted.

are there fixes these problems? first 1 kind of undermines whole point of scripting , i'm afraid second 1 cause unforeseen problems.

sub convertrtftodocx()      set oword = createobject("word.application")      application.filedialog(msofiledialogfolderpicker)         .title = "select folder..."         .show         myfolder = .selecteditems.item(1)     end      mywildcard = inputbox(prompt:="enter wild card...")      mydocs = dir(myfolder & "\" & mywildcard)      while mydocs <> ""         debug.print mydocs         set odoc = oword.documents.open(myfolder & "\" & mydocs)         odoc.saveas myfolder & "\" & left(mydocs, len(mydocs) - 4) & ".docx", _             wdformatxmldocument         mydocs = dir()     wend     oword.quit  end sub 

the following code works.

sub convertrtftodocx()      application.filedialog(msofiledialogfolderpicker)         .title = "select folder..."         .show         myfolder = .selecteditems.item(1)     end      mywildcard = inputbox(prompt:="enter wild card...")      mydocs = dir(myfolder & "\" & mywildcard)      while mydocs <> ""         documents.open filename:=myfolder & "\" & mydocs, confirmconversions:=false         activedocument.saveas2 filename:=myfolder & "\" & left(mydocs, len(mydocs) - 4) & ".docx", _             fileformat:=wdformatdocumentdefault, _             compatibilitymode:=wdcurrent         activedocument.close savechanges:=false         mydocs = dir()     wend  end sub 

i did restructuring (e.g., use activedocument instead of creating own object), real changes did to

  1. set confirmconversions:=false on open
  2. use saveas2 method , set fileformat:=wdformatdocumentdefault , compatibilitymode:=wdcurrent

i guess both of these can set default (i'm overwhelmed office options , leave defaults).


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -