closing a workbook
Hello, I have a problem.I want to have a excel macro which
makes the below job:
I am copying some cells from an excel workbook(when I copy
the cells the workbook opens), after that I want to paste these cells
to another workbook. After copying, before pasting; I want to close the
workbook which I copied the cells. I wrote the below code for this aim
but it gave an error,
Workbooks("C:\butce34\Belgelerim\OZG\haf_aliskanli kmart1.1.xls").Close
If u help me , I w,ll be very glad. Thanks.
Whole code is :
Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
Sub copy_to_another_workbook()
Dim sourceRange As Range
Dim destrange As Range
Dim destWB As Workbook
Dim sourceWB As Workbook
Dim a As Integer
Dim Lr As Long
Dim d1 As Long
Dim d2 As Long
Dim r1 As Integer
Dim r2 As Integer
On Error Resume Next
Application.ScreenUpdating = False
Set sourceWB = ThisWorkbook
Set destWB = Workbooks.Open("C:\Documents and
Settings\butce34\Belgelerim\OZG\haf_aliskanlikmart 1.1.xls")
Lr = LastRow(destWB.Worksheets("haf_alikanlik"))
Set destrange = destWB.Worksheets("haf_alikanlik").Range("A1:Z" &
Lr)
Set sourceRange = sourceWB.Worksheets("Sayfa2").Range("A1: A1")
destrange.Copy sourceRange
Application.ScreenUpdating = True
Workbooks("C:\butce34\Belgelerim\OZG\haf_aliskanli kmart1.1.xls").Close
d1 = Range("B1").Value
d2 = Range("C1").Value
r1 = Sheets("sayfa2").Cells.Find(d1).Row
r2 = Sheets("sayfa2").Cells.Find(d2).Row
Sheets("sayfa1").Rows(r1 & ":" & r2).Select
Selection.Copy
End Sub
|