Hi all,
As a noob with VBA I am trying to expand on my newly found skills, and recently came across an exercise where I had to save a Word document as text. The text file then has to be opened, the contents copied and pasted in an Excel sheet. Whilst I got the last part of the code right (in a separate module), I have been struggling with the first part of opening the Word document and saving it as text. I copied code from a previous post related to the same subject matter and amended it to my needs, but am still stuck. I get a "Type mismatch" error on the red line of code below. Any assistance with this would be greatly appreciated.
As a noob with VBA I am trying to expand on my newly found skills, and recently came across an exercise where I had to save a Word document as text. The text file then has to be opened, the contents copied and pasted in an Excel sheet. Whilst I got the last part of the code right (in a separate module), I have been struggling with the first part of opening the Word document and saving it as text. I copied code from a previous post related to the same subject matter and amended it to my needs, but am still stuck. I get a "Type mismatch" error on the red line of code below. Any assistance with this would be greatly appreciated.
Code:
Sub CreateText()
Dim psWorkbookCurrentWorkingDirectory As String
Dim psNextFullChecklistFileName As String
Dim psNextChecklistFileName As String
Dim wdApplication As Object
[COLOR=#ff0000]Set wdDocument = New Workbook.Document[/COLOR]
On Error Resume Next
Set wdApplication = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set wdApplication = CreateObject("Word.Application")
End If
On Error GoTo 0
Set wdDocument = wdApplication.Documents.Open(Range("Web_folder") & Range("Query_file") & ".docx")
wdApplication.Visible = True
wdDocument.SaveAs Filename:=Range("Quote_folder") & Range("Quote_file") & ".txt", _
FileFormat:=wdFormatText, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False, Encoding:=1252, InsertLineBreaks:=False, _
AllowSubstitutions:=False, LineEnding:=wdCRLF
wdDocument.Close
wdApplication.Quit
Set wdApplication = Nothing
Set wdDocument = Nothing
End Sub