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

I am having an issue with figuring out how to close a workbook. I know
how to close a workbook when the filename is constant/known but not
when it is dynamic. The scenario is that my Main macro reads in a text
file causing a temporary workbook to be created. It then copies data
from the temp wb into the main wb. Problem is i cannot close the temp
wb because its name constantly changes (book1, book2, etc. ). The
soulution i am looking for is to be able to specify the name of the
temp wb at creation, or capture its name for closing once the data has
been copied to the main wb successfully. I suspect the Freefile
variable is the cause of the temp wb changing from Book1 to Book2 and
so on. Is there a way to set the temp wb name somewhere?

Thanks,

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default workbook question...

Hi Waxaholic,

Try something like:

'=============
Public Sub Tester001()
Dim WB As Workbook
Const sStr As String = "C:\YourFile.txt" '<<==== CHANGE
Set WB = Workbooks.Open(sStr)

'Your processing code
WB.Close SaveChanges:=False

End Sub
'<<=============


---
Regards,
Norman


"Waxaholic" wrote in message
oups.com...
I am having an issue with figuring out how to close a workbook. I know
how to close a workbook when the filename is constant/known but not
when it is dynamic. The scenario is that my Main macro reads in a text
file causing a temporary workbook to be created. It then copies data
from the temp wb into the main wb. Problem is i cannot close the temp
wb because its name constantly changes (book1, book2, etc. ). The
soulution i am looking for is to be able to specify the name of the
temp wb at creation, or capture its name for closing once the data has
been copied to the main wb successfully. I suspect the Freefile
variable is the cause of the temp wb changing from Book1 to Book2 and
so on. Is there a way to set the temp wb name somewhere?

Thanks,



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default workbook question...

I tried this but it is requiring a fixed name of the source text file
which changes periodically.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default workbook question...

I figured this out. I just created a new sheet in the current workbook
and used it as a scrath pad, then deleted it.

Waxaholic wrote:
I tried this but it is requiring a fixed name of the source text file
which changes periodically.


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
Workbook Question Renee Excel Discussion (Misc queries) 2 March 12th 10 06:45 PM
Workbook question... Maurice Excel Discussion (Misc queries) 1 July 21st 09 12:03 AM
workbook question Jackie Excel Discussion (Misc queries) 9 August 13th 06 09:25 PM
Workbook Name question Stuart[_5_] Excel Programming 3 April 10th 04 07:35 PM
Question for Experts: Opening workbook with workbook references Chris Excel Programming 0 September 11th 03 07:05 PM


All times are GMT +1. The time now is 10:26 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"