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.WorksheetFunct ion.VLooku p(selected Value, Sheets("Template").Range(" A1:A30"), 1, False)
fileLocation = Application.WorksheetFunct ion.VLooku p(selected Value, Sheets("Template").Range(" A1:B30"), 2, False)
Subject = Application.WorksheetFunct ion.VLooku p(selected Value, Sheets("Template").Range(" A1:C30"), 3, False)
personName = Cells(Application.ActiveCe ll.Row, 6).Value & " " & Cells(Application.ActiveCe ll.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.Applica tion")
WA.Documents.Open (pathh)
WA.Visible = True
WA.Selection.Find.ClearFor matting
WA.Selection.Find.Replacem ent.ClearF ormatting
With WA.Selection.Find
.Text = "xyz"
.Replacement.Text = Cells(Application.ActiveCe ll.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
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.WorksheetFunct
fileLocation = Application.WorksheetFunct
Subject = Application.WorksheetFunct
personName = Cells(Application.ActiveCe
If selectedValue = templateValues Then
Call from(fileLocation)
'Call Client_Mails(fileLocation,
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.Applica
WA.Documents.Open (pathh)
WA.Visible = True
WA.Selection.Find.ClearFor
WA.Selection.Find.Replacem
With WA.Selection.Find
.Text = "xyz"
.Replacement.Text = Cells(Application.ActiveCe
.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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER