engineer0603
New Member
- Joined
- Jun 23, 2011
- Messages
- 1
I am trying to write some code that upon pushing a command button, it prompts the user for the number of pics they want to insert into a word doc and then initiates a loop that opens a browse window to let the user choose each picture. The issue I am having is that after the user chooses the picture, Word gives me the error “Run-time error ‘5174’. This file could not be found. (-1).” And then subsequently tries to open the .jpg or .bmp file in a separate word file.
What is wrong in the code below that will not allow the browsed-for picture to be inserted into my word document?
Private Sub CommandButton5_Click()
'Adds pictures to document
Dim Count1 As Integer
Dim PictureNow As String
Dim InsertPics1 As Integer
InsertPics1 = InputBox("Question", _
"InsertPicsTitle", "How many pictures would you like to add?")
While Count1 < InsertPics1
Selection.GoTo Name:="Check82"
Selection.EndKey Unit:=wdLine
Selection.TypeParagraph
Selection.InsertFile FileName:=Dialogs(wdDialogFileOpen).Show
Selection.EndKey Unit:=wdLine
Selection.TypeParagraph
Count1 = Count1 + 1
Wend
End Sub
Aside from the code above I have also tested the code
Selection.InlineShapes.AddPicture FileName:="N:\Test_Pic.bmp", _
LinkToFile:=False, SaveWithDocument:=True
Which works fine if I want to insert a pre-determined picture, but this does not allow the user to browse to find that picture and I have not figured out how to incorporate the “browse” function into the above code.
Any help to accomplish my goal would be appreciated.
Thanks!
What is wrong in the code below that will not allow the browsed-for picture to be inserted into my word document?
Private Sub CommandButton5_Click()
'Adds pictures to document
Dim Count1 As Integer
Dim PictureNow As String
Dim InsertPics1 As Integer
InsertPics1 = InputBox("Question", _
"InsertPicsTitle", "How many pictures would you like to add?")
While Count1 < InsertPics1
Selection.GoTo Name:="Check82"
Selection.EndKey Unit:=wdLine
Selection.TypeParagraph
Selection.InsertFile FileName:=Dialogs(wdDialogFileOpen).Show
Selection.EndKey Unit:=wdLine
Selection.TypeParagraph
Count1 = Count1 + 1
Wend
End Sub
Aside from the code above I have also tested the code
Selection.InlineShapes.AddPicture FileName:="N:\Test_Pic.bmp", _
LinkToFile:=False, SaveWithDocument:=True
Which works fine if I want to insert a pre-determined picture, but this does not allow the user to browse to find that picture and I have not figured out how to incorporate the “browse” function into the above code.
Any help to accomplish my goal would be appreciated.
Thanks!