Range -> Bookmark

beczer

New Member
Joined
Nov 21, 2016
Messages
49
Hi there

I have a small problem. Could you tell me / advice how to assign a Range to Bookmark from Sheet1 in below case ?

thanks!

Code:
Sub SomeSub()Dim r As Integer
Dim wdApp As Word.Application
Dim doc As Word.Document
Dim wkbCRMExt As Workbook
Dim wksCRMExt As Worksheet, wksCRM As Worksheet
    Set wksCRM = ActiveSheet
    Set wkbCRMExt = Workbooks.Open(Environ("UserProfile") & "\Desktop\CRM.xlsx")
    Set wksCRMExt = wkbCRMExt.Sheets(1)
    Set wdApp = New Word.Application
    Set doc = wdApp.Documents.Open(Environ("UserProfile") & "\" & ThisWorkbook.Sheets("Path").Cells(1))
    With ThisWorkbook.Worksheets("CRM2")
    [B]With ThisWorkbook.Worksheets("Sheet1")
[/B]

        For r = 1 To 5
            doc.Bookmarks(wksCRM.Cells(r, "A").Value).Range.Text = wksCRMExt.Cells(r, "B").Value
            doc.Bookmarks(.Cells(r, "A").Value).Range.Text = .Cells(r, "B").Value
            [B]doc.Bookmarks(.range A1:A20)[/B]

        Next
    End With
    doc.SaveAs2 Environ$("UserProfile") & "\Desktop\Doc1.docx"
    doc.Close False
  
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
You have messed up the wb sheet identification. You have 2 "With"'s and only one "End With". It's not clear where your data is coming from. Maybe provide a little more info about exactly what U want to accomplish (specific sheets etc). HTH. Dave
 
Upvote 0
I take Data from 2 Excel files.
1. CRM - external Excel file: Sheet1 (sheet)
2. Current opened Excel file: CRM2 (sheet)

I would like to take a Data Range from 2nd sheet - Sheet1 in Current opened Excel file
 
Upvote 0
Please just indicate exactly what the sheet name is and where the data range is that U want to put in the book marks. What range of data from what sheet goes into what bookmark? It's not clear to me. Dave
 
Upvote 0
Did it occur to you to do a search? There are plenty of threads showing how to populate Word bookmarks, including some very recent ones...

There is even at least one post where I provided you with code for that!!!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,803
Messages
6,174,687
Members
452,577
Latest member
Filipzgela

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top