+ Reply to Thread
Results 1 to 6 of 6

Getting run-time error 91 object variable with block variable not set

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Getting run-time error 91 object variable with block variable not set

    Hi friends,

    I want to insert an image in the word file in place of book mark. I’m getting run-time error 91 object variable with block variable not set.

    Any help will be highly appreciated.

    Thanking you in anticipation.
    Attached Files Attached Files
    Sincerely,

    mso3

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Getting run-time error 91 object variable with block variable not set

    Can you post the code?

    PS The reason I'm asking is because I won't be downloading any attachments from this forum until the security issues are dealt with.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Getting run-time error 91 object variable with block variable not set

    Hi Norie,

    Here is a code:

    Option Explicit
    
    Sub AddImage()
    Dim intChoice As Integer
    Dim strPath As String
    Dim document As document
    
    Set document = document.Open("C:\Users\Admin\Documents\CONTACT DIRECTORY\INPUT\ADD IMAGE.docx")
    
    Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
    intChoice = Application.FileDialog(msoFileDialogOpen).Show
    If intChoice <> 0 Then
        strPath = Application.FileDialog( _
            msoFileDialogOpen).SelectedItems(1)
    End If
    
    Selection.GoTo What:=wdGoToBookmark, Name:="bm1"
    Selection.InlineShapes.AddPicture Filename:= _
        strPath, LinkToFile:=False, _
        SaveWithDocument:=True
    End Sub
    Thank you.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Getting run-time error 91 object variable with block variable not set

    Eh, what's 'document'?

  5. #5
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Getting run-time error 91 object variable with block variable not set

    I have a word document in which I want to insert a image in place of book mark.
    First I want to open a word document 'ADD IMAGE.docx' from excel then want to open a dialog box to select a 'jpg' file from the folder to insert it in the word document.

    Hope this help you to amend the code positively.

  6. #6
    Forum Contributor
    Join Date
    06-29-2014
    Location
    India
    MS-Off Ver
    2010 Windows 10 64 bits
    Posts
    1,269

    Re: Getting run-time error 91 object variable with block variable not set

    The problem is solved.

    Option Explicit
    
    Sub AddImage()
    Dim intChoice As Integer
    Dim strPath As String
    Dim objWord As Object
    
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = True
    objWord.Documents.Open "C:\Users\Admin\Documents\CONTACT DIRECTORY\OUTPUT\ADD IMAGE.docx"
    objWord.Application.Activate
    
    Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
    intChoice = Application.FileDialog(msoFileDialogOpen).Show
    If intChoice <> 0 Then
        strPath = Application.FileDialog( _
            msoFileDialogOpen).SelectedItems(1)
    End If
    
    'Selection.GoTo What:=wdGoToBookmark, Name:="bm1"
    objWord.Selection.GoTo What:=wdGoToBookmark, Name:="bm1"
    objWord.Selection.InlineShapes.AddPicture Filename:= _
        strPath, LinkToFile:=False, _
        SaveWithDocument:=True
        objWord.ActiveDocument.Close
        MsgBox "Done"
    End Sub
    Thanking you,

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Run-time error '91': Object variable or With block variable not set when closing userform
    By bishoposiris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2016, 08:59 AM
  2. Replies: 0
    Last Post: 04-16-2013, 07:15 AM
  3. Replies: 6
    Last Post: 12-21-2012, 08:03 AM
  4. Replies: 1
    Last Post: 09-25-2012, 08:03 PM
  5. [SOLVED] Intermittent Run-time Error 91: Object Variable or With Block variable not set
    By fraanchtoast in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-29-2012, 10:11 AM
  6. Run-time error 91 Object variable or with block variable not set
    By Janoose in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-09-2010, 08:27 AM
  7. Run-time error '91': Object variable or With block variable not set
    By Snoopy2010 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-31-2010, 01:55 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1