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.
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.
Sincerely,
mso3
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.
Hi Norie,
Here is a code:
Thank you.![]()
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
Eh, what's 'document'?
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.
The problem is solved.
Thanking you,![]()
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
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks