PDA

View Full Version : vba help- copy excel worksheet to word by browsing for excel file



sarveshspace
11-11-2020, 09:07 PM
hello!
I would like to copy a sheet from an excel file to word . I would like to place the first sheet from the excel at a bookmark location in word.
I want to browse for the file from word and select the file and then paste it at the bookmark.

Private Sub CommandButton4_Click()
Dim FileToOpen As Variant
Dim OpenBook As Excel.Workbook
Application.ScreenUpdating = False
FileToOpen = Application.getopenfilename(Title:="Browse for your File & Import overlay", FileFilter:="Excel Files (*.xls*),*xls*")
If FileToOpen <> False Then
Set OpenBook = Application.Workbooks.Open(FileToOpen)
OpenBook.Sheets(1).Copy
ActiveDocument.Bookmarks("srspic").PasteSpecial xlPasteValues
OpenBook.Close False


End If
Application.ScreenUpdating = True
End Sub


for some reason, i get user type not defined error at excel.workbook.
i have enabled microsoft office 16 object library in references.

I would appreciate any help!
thanks!

I have attached the excel file for reference, I want to copy the overlay sheet from excel to word .