Link to home
Start Free TrialLog in
Avatar of rdy123 rdy
rdy123 rdy

asked on

location range

hi,

in one  macro i gave the file location as,
fileLocation = Application.WorksheetFunction.VLookup(selectedValue, Sheets("Template").Range("A1:B30"), 2, False)

so it pulls from the excel sheet template second column.(where the file location pulls from that range "C:\Templates\xxx.docx")

in other macro i gave as
 pathh = "C:\Templates\xxx.docx"

is there any option of giving pathh ="fileLocation" so that it could pick from the filelocation directly instead of giving  pathh = "C:\Templates\xxx.docx"

i tried giving this but it is not working,any suggestions please.

code looks like

Sub from()

Dim pathh As String
Dim pathhi As String
Dim oCell  As Integer
Dim WA As Object

pathh = "fileLocation"

Set WA = CreateObject("Word.Application")
WA.Documents.Open (pathh)
WA.Visible = True
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

How about:
WA.Documents.Open (Application.WorksheetFunction.VLookup(selectedValue, Sheets("Template").Range("A1:B30"), 2, False))

Open in new window

Avatar of rdy123 rdy
rdy123 rdy

ASKER

thank you,but i am getting runtime error 1004
In which module did you put the code?
Try putting it in a regular module.
ASKER CERTIFIED SOLUTION
Avatar of Joe Howard
Joe Howard
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial