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


I'm after some advice and was wondering if anyone out there could help.

I'm needing to write a macro that selects a sheet in a workbook, an
then copies and pastes the values into a new sheet. OK, so far.

But here's where the problem comes. The file the orginal sheet i
located in could have various different filenames, and when I've bee
testing recording macros, the filename is being recorded in the macr
due to the switching between workbooks.

I have found a formula which shows the filename on the worksheet, bu
don't know how to feed this information into VBA.


Code
-------------------
=MID(CELL("filename",A1),FIND("[",CELL("filename",A1))+1,FIND("]",CELL("filename",A1))-FIND("[",CELL("filename",A1))-1
-------------------


Is this the right way of going about this, or is there a better, o
easier way of doing it?

Cheers,

Barella :confused

--
barell
-----------------------------------------------------------------------
barella's Profile: http://www.excelforum.com/member.php...fo&userid=1550
View this thread: http://www.excelforum.com/showthread.php?threadid=27078

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Exporting to a new workbook

Barella,

You can get the filename of the original workbook simply by:

OrigFileName = ActiveWorkbook.Name

HTH,
Nikos

"barella" wrote in message
...

I'm after some advice and was wondering if anyone out there could help.

I'm needing to write a macro that selects a sheet in a workbook, and
then copies and pastes the values into a new sheet. OK, so far.

But here's where the problem comes. The file the orginal sheet is
located in could have various different filenames, and when I've been
testing recording macros, the filename is being recorded in the macro
due to the switching between workbooks.

I have found a formula which shows the filename on the worksheet, but
don't know how to feed this information into VBA.


Code:
--------------------

=MID(CELL("filename",A1),FIND("[",CELL("filename",A1))+1,FIND("]",CELL("file
name",A1))-FIND("[",CELL("filename",A1))-1)
--------------------


Is this the right way of going about this, or is there a better, or
easier way of doing it?

Cheers,

Barella


--
barella
------------------------------------------------------------------------
barella's Profile:

http://www.excelforum.com/member.php...o&userid=15506
View this thread: http://www.excelforum.com/showthread...hreadid=270782



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Exporting to a new workbook

While a variable can be supplied as the argument to workbooks collection, if
there are multiple workbooks open, how would the macro know which one you
wanted to copy to?

As your formula shows, a workbook has no problem knowing its own name, but a
macro would have to know how to determine which workbook is the destination
workbook if you don't supply a workbook name.

--
Regards,
Tom Ogilvy

"barella" wrote in message
...

I'm after some advice and was wondering if anyone out there could help.

I'm needing to write a macro that selects a sheet in a workbook, and
then copies and pastes the values into a new sheet. OK, so far.

But here's where the problem comes. The file the orginal sheet is
located in could have various different filenames, and when I've been
testing recording macros, the filename is being recorded in the macro
due to the switching between workbooks.

I have found a formula which shows the filename on the worksheet, but
don't know how to feed this information into VBA.


Code:
--------------------

=MID(CELL("filename",A1),FIND("[",CELL("filename",A1))+1,FIND("]",CELL("file
name",A1))-FIND("[",CELL("filename",A1))-1)
--------------------


Is this the right way of going about this, or is there a better, or
easier way of doing it?

Cheers,

Barella


--
barella
------------------------------------------------------------------------
barella's Profile:

http://www.excelforum.com/member.php...o&userid=15506
View this thread: http://www.excelforum.com/showthread...hreadid=270782



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
Exporting Dave2 Excel Discussion (Misc queries) 0 December 10th 07 02:26 AM
exporting njanja Excel Discussion (Misc queries) 4 April 12th 06 12:23 AM
Exporting certain cells to new workbook Smokes Excel Discussion (Misc queries) 0 March 21st 06 08:11 PM
Exporting Access data to different worksheets on the same workbook chill[_2_] Excel Programming 1 December 5th 03 12:14 PM
Help exporting worksheets/data to a workbook. Tbird Excel Programming 2 October 22nd 03 07:18 PM


All times are GMT +1. The time now is 09:35 AM.

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"