Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 51
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing Hidden Workbook when Active Workbook is Closed SusanK521 Excel Programming 5 September 24th 05 12:27 AM
Help with closing down a workbook?? Don Excel Worksheet Functions 1 May 9th 05 04:05 AM
Closing workbook Ed Excel Programming 4 February 6th 04 03:41 PM
closing excel after closing a workbook CWalsh[_2_] Excel Programming 3 January 21st 04 03:33 PM
closing workbook Sam Dickins Excel Programming 1 November 27th 03 03:43 PM


All times are GMT +1. The time now is 11:02 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"