Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Open Copy Close

I have these two Macro's at present: -

Sub ListFiles()
F = Dir("C:\*.XLS")
Do While Len(F) 0
ActiveCell.Formula = F
ActiveCell.Offset(1, 0).Select
F = Dir()
Loop
End Sub

Sub CopyInfo()
Workbooks.Open Filename:=Range("A1").Value
Range("A:B").Copy Destination:=Workbooks("Book1").Range("B:C")
Workbooks.Close Filename:=Range("A1").Value
MsgBox ("Completed Copying")

End Sub

As you can see I want the Macro to open the file name in A1 then copy
the information, then paste it into Book1.xls, then cose the Filename
in A1.

So far it opens the workbook, but won't close it. I dont think I can
use the close command here, any ideas?


---
Message posted from http://www.ExcelForum.com/

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Open Copy Close

Hi
Try this

Sub CopyInfo()
Dim wbOne as Workbook
Set wbOne = Workbooks.Open Filename:=Range("A1").Value
Range("A:B").Copy Destination:=Workbooks("Book1").Range("B:C")
wbOne.Close
MsgBox ("Completed Copying")
End Sub

Also ActiveWorkbook.close should work


ianripping wrote in message
...
I have these two Macro's at present: -

Sub ListFiles()
F = Dir("C:\*.XLS")
Do While Len(F) 0
ActiveCell.Formula = F
ActiveCell.Offset(1, 0).Select
F = Dir()
Loop
End Sub

Sub CopyInfo()
Workbooks.Open Filename:=Range("A1").Value
Range("A:B").Copy Destination:=Workbooks("Book1").Range("B:C")
Workbooks.Close Filename:=Range("A1").Value
MsgBox ("Completed Copying")

End Sub

As you can see I want the Macro to open the file name in A1 then copy
the information, then paste it into Book1.xls, then cose the Filename
in A1.

So far it opens the workbook, but won't close it. I dont think I can
use the close command here, any ideas?


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Open Copy Close

Set wbOne = Workbooks.Open Filename:=Range("A1").Value forms a synta
error

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Open Copy Close

Sorry, stupid mistake on my part!!!
Set wbOne = Workbooks.Open(Filename:=Range("A1").Value)
should sort it
;-)


ianripping wrote in message
...
Set wbOne = Workbooks.Open Filename:=Range("A1").Value forms a syntax
error.


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Open Copy Close

OK I've got it its like this

Workbooks.Open Filename:=Range("A1").Value
Range("A:A").Select
Selection.Copy
ActiveWorkbook.Close SaveChanges:=False
Windows("Book1.xls").Activate
Range("C:C").Select
ActiveSheet.Paste
MsgBox ("Completed Copying")

BUT! Excel asks do you want to copy this large amount of info blah
blah

Then do you want to paste this info even though the target cell isn't
as big blah blah


Is there a way to turn off these prompts?


---
Message posted from http://www.ExcelForum.com/



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Open Copy Close

I haven't been able to recreate your problem but you could try inserting
this line before the copy command
Application.DisplayAlerts = False
Set back to True at the end of the routine
;-)

ianripping wrote in message
...
OK I've got it its like this

Workbooks.Open Filename:=Range("A1").Value
Range("A:A").Select
Selection.Copy
ActiveWorkbook.Close SaveChanges:=False
Windows("Book1.xls").Activate
Range("C:C").Select
ActiveSheet.Paste
MsgBox ("Completed Copying")

BUT! Excel asks do you want to copy this large amount of info blah
blah

Then do you want to paste this info even though the target cell isn't
as big blah blah


Is there a way to turn off these prompts?


---
Message posted from http://www.ExcelForum.com/



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
Open a workbook, Copy several cells, then Close the previously openedworkbook [email protected] Excel Worksheet Functions 0 April 9th 08 11:54 PM
How do I close all open spreadsheets at once? cbh Excel Discussion (Misc queries) 13 January 12th 08 11:30 PM
Macro to close workbook and re-open new copy Dave Lagergren Excel Discussion (Misc queries) 2 February 28th 07 10:11 PM
run macro on close & open Stu[_27_] Excel Programming 3 October 15th 03 02:09 PM
Close database if it is open Tod Excel Programming 0 July 18th 03 07:19 PM


All times are GMT +1. The time now is 11:58 PM.

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

About Us

"It's about Microsoft Excel"