Results 1 to 2 of 2

Thread: Error -- Object variable or With block not set

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2000
    Posts
    12
    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

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width