String as dynamic value [MailMerge]

Mike2502

Board Regular
Joined
Jan 19, 2020
Messages
143
Office Version
  1. 2010
Hi All,

I'm trying to have a variable for Column D and Row X however I'm unsure of how to go about this. As the value in Column D Row X will be based on each row it can be either ABC or XYZ.

Dependent on the value in each column the mail merge will use a different document for each rows mail merge.

At the moment I have the below but unsure how to get it as dynamic :/ !

VBA Code:
    'Mailmerge for Sheet1
    Dim wdc
    Dim xc
    Dim ContractType As Range
    Dim RowTarget1 As Long

    Dim X as integer

    Dim Worksheet As Worksheet
    Set Worksheet= ActiveSheet

    Set ContractType = ActiveSheet.Cells(x, 4)
    X = 2
    
    Set wdc = CreateObject("word.application")
    wdc.Application.documents.Open "\Templates\" & ContractType & ".docm"
    
    wdc.Application.Visible = False
    Application.ScreenUpdating = False
    wdc.Application.Run "Template1"
    Set wdc = Nothing
    
    MsgBox ("Mail Merge Completed")
    Application.ScreenUpdating = True
Any help is appreciated - thanks
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
UPDATE - I keep getting an error I believe this would be workable?

VBA Code:
Sub MailMerge()
    'Mailmerge for Sheet1
    Dim wdc
    Dim xc
    Dim ContractType As Range
    Dim wsWorksheet As Worksheet
    Set wsWorksheet = Sheets("Data")
    
    With wsWorksheet
    
    Set ContractType = Range("D" & Rows.Count).End(xlUp).Select

    Set wdc = CreateObject("word.application")
    wdc.Application.documents.Open "Location" & ContractType & ".docm"
    
    wdc.Application.Visible = False
    Application.ScreenUpdating = False
    wdc.Application.Run "Template"
    Set wdc = Nothing
    
    MsgBox ("Mail Merge Completed")
    Application.ScreenUpdating = True
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,556
Messages
6,114,284
Members
448,562
Latest member
Flashbond

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