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

asked on

macro for same location path

Hi,

in excel file a Sheet named-Template,i gave a location in B2 cell,where i always go the location to open the file,in one macro i gave the filelocation as below code,and in same macro i am calling other macro "Call from(fileLocation)" in this macro when i give path directly it is pulling the data but when i give as filelocation it is not pulling the data.
any modifications to be done to pull the data from name filelocation. please suggest.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim selectedValue As String
Dim templateValues As String
Dim fileLocation As String
Dim personName As String
Dim Subject As String


selectedValue = ActiveCell.Formula

On Error GoTo SubEnd
templateValues = Application.WorksheetFunction.VLookup(selectedValue, Sheets("Template").Range("A1:A30"), 1, False)
fileLocation = Application.WorksheetFunction.VLookup(selectedValue, Sheets("Template").Range("A1:B30"), 2, False)
Subject = Application.WorksheetFunction.VLookup(selectedValue, Sheets("Template").Range("A1:C30"), 3, False)
personName = Cells(Application.ActiveCell.Row, 6).Value & " " & Cells(Application.ActiveCell.Row, 7).Value

If selectedValue = templateValues Then

Call from(fileLocation)
'Call Client_Mails(fileLocation, Subject)

End If
SubEnd:
End Sub


Sub from(fileLocation As String)

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

pathh = "fileLocation"
'pathh = "C:\temp\xxx.docx"

Set WA = CreateObject("Word.Application")
WA.Documents.Open (pathh)
WA.Visible = True

WA.Selection.Find.ClearFormatting
WA.Selection.Find.Replacement.ClearFormatting
With WA.Selection.Find
        .Text = "xyz"
        .Replacement.Text = Cells(Application.ActiveCell.Row, 15).Value
        .Forward = True
        .Wrap = wdFindAsk
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
   
     End With
WA.Selection.Find.Execute replace:=wdReplaceAll



End Sub
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
Avatar of rdy123 rdy
rdy123 rdy

ASKER

thank you so much,its working...