Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting VBA code to work in VB.NET???

Status
Not open for further replies.

dmoonme

MIS
Jul 21, 2004
33
0
0
US
Hi here's my VBA code that I want to use in VB.NET.
I'm do not know the new syntax's in VB.NET in order for this to work. It basically converts .doc files to .rtf.

PLEASE HELP.

Code:
Dim aDoc
Dim tempFilename As String = "c:\test.txt"
'Application.ScreenUpdating = False
aDoc = Dir("c:\test\*.doc")
Do While aDoc <> ""
    Documents.Open(FileName:="c:\Test\" & aDoc)
' strip off .doc from the name
    tempFilename = Left(aDoc, (Len(aDoc) - 4))
    ActiveDocument.SaveAs(FileName:="c:\test\rtf\" & tempFilename, fileformat:=wdFormatRTF)
    ActiveDocument.Close(wdDoNotSaveChanges)
    aDoc = Dir()
Loop
Application.ScreenUpdating = True
[\code]
 
Thanks for taking a look... I figured it out.

Here it is:


Code:
Dim oWord As Word.ApplicationClass
'Start Word and open the document.
oWord = CreateObject("Word.Application")
oWord.Visible = False 'set to true to see Word open up.

Dim aDoc
Dim tempFilename As String
oWord.Application.ScreenUpdating = False
'aDoc = Dir("c:\test\*.doc")
aDoc = Dir(strPathName & "\*.doc")
Do While aDoc <> ""
    'oWord.Documents.Open(FileName:="c:\Test\" & aDoc)
    oWord.Documents.Open(FileName:=strPathName & "\" & aDoc)
' strip off .doc from the name
    tempFilename = Left(aDoc, (Len(aDoc) - 4))

    oWord.ActiveDocument.SaveAs(FileName:="c:\test\rtf\" & tempFilename, fileformat:=108)
    'save files to RTF format.  108 is RTF, 106 is .doc, 

    oWord.ActiveDocument.Close()
    aDoc = Dir()
Loop
oWord.Application.ScreenUpdating = True

  'Quit Word.
        oWord.Quit()
        System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord)
        oWord = Nothing

        GC.Collect()
 
Thanks for taking a look... I figured it out.

Here it is:


Code:
Sub ConverToRtf()
Dim oWord As Word.ApplicationClass
'Start Word and open the document.
oWord = CreateObject("Word.Application")
oWord.Visible = False 'set to true to see Word open up.

Dim aDoc
Dim tempFilename As String
oWord.Application.ScreenUpdating = False
'aDoc = Dir("c:\test\*.doc")
aDoc = Dir(strPathName & "\*.doc")
Do While aDoc <> ""
    'oWord.Documents.Open(FileName:="c:\Test\" & aDoc)
    oWord.Documents.Open(FileName:=strPathName & "\" & aDoc)
' strip off .doc from the name
    tempFilename = Left(aDoc, (Len(aDoc) - 4))

    oWord.ActiveDocument.SaveAs(FileName:="c:\test\rtf\" & tempFilename, fileformat:=108)
    'save files to RTF format.  108 is RTF, 106 is .doc, 

    oWord.ActiveDocument.Close()
    aDoc = Dir()
Loop
oWord.Application.ScreenUpdating = True

'Quit Word.
oWord.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(oWord)
oWord = Nothing
GC.Collect()

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top