-
I receive an Object variable or With Block not set error sometimes when running the following code:
Function wordConversion(sFileName As String)
If wordApp Is Nothing Then
Set wordApp = CreateObject("word.Application")
End If
Set wordDoc = wordApp.Documents.Open(sFileName)
<<this is where the error gets highlighted>>
With Documents.Application.Selection
.WholeStory
.Font.Name = "Ariel"
.Font.Size = 9
End With
ActiveDocument.PageSetup.Orientation = wdOrientLandscape
sFileName = nameChange(sFileName)
ActiveDocument.SaveAs sFileName, wdFormatDocument
ActiveDocument.Close
Set wordDoc = Nothing
End Function
Any ideas why this error would occur only occasionally, and how to correct the problem?
Thanks
-
You get that "Object variable or With Block not set" error if the Documents.Application.Selection does not return any object. I don't know how to use word in vb but so I don't know but I think this Selection will return nothing if there isnt anything selected.