View Single Post
 
Old 10-29-2015, 01:02 AM
PRA007's Avatar
PRA007 PRA007 is offline Windows 7 32bit Office 2010 32bit
Competent Performer
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default First Excel Macro!!!!!!!!!!

Can we assign path If I dont want to open any of the file and want to run macro from third macro enabled doccument?
Yes:

I got the solution using simple excel tutorial
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim rSrc As Long, rTgt As Long, StrTmp As String
Dim xlShtTgt As Worksheet, xlShtSrc As Worksheet, xlRng As Range
On Error Resume Next
Set wkb = Workbooks.Open("C:\Users\rahulkumar.patel\Desktop\Sheet1.xlsx")
Set wkb1 = Workbooks.Open("C:\Users\rahulkumar.patel\Desktop\FE.xlsx")
Set xlShtTgt = Workbooks("Sheet1.xlsx").Sheets(1)
Set xlShtSrc = Workbooks("FE.xlsx").Sheets(1)
With xlShtTgt
  Set xlRng = .Range("A1:A" & .UsedRange.Cells.SpecialCells(xlCellTypeLastCell).Row)
End With
With xlShtTgt
  For rTgt = 1 To .UsedRange.Cells.SpecialCells(xlCellTypeLastCell).Row
    StrTmp = .Cells(rTgt, 3).Value
    With xlShtSrc
      rSrc = .Range("A1:A" & .UsedRange.Cells.SpecialCells(11).Row).Find( _
      What:=StrTmp, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
      MatchCase:=True, SearchFormat:=False).Row
    End With
    .Cells(rTgt, 3).Value = xlShtSrc.Cells(rSrc, 2).Value
  Next
  With .Columns(3)
    .WrapText = False
    .AutoFit
  End With
End With
Application.ScreenUpdating = False
wkb.Close SaveChanges:=True
wkb1.Close SaveChanges:=True
End Sub
Reply With Quote