Excel Macro - figure out current file name

joe621

New Member
Joined
Oct 23, 2006
Messages
1
Hi Everybody,

I'm currently trying to teach myself a little vb scripting for a project i'm working on.

I've setup a macro to copy/paste data from one spreadsheet to another.

i have the end user opening a template , enter data, then saving the spreadsheet. I then want them to run this macro to copy certain cells from this sheet to another spreadsheet.

i am trying to figure out how to get the name of the spreadsheet that i'm doing the copying from. since it'll be different every time i cant hard code the file name in the script.

I'm also trying to figure how how to switch "focus" between the 2 spreadsheets so that i can copy from one and paste to the other back and forth.

Thanks Much in Advance,

Joe
 

Some videos you may like

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
75,915
Office Version
  1. 365
Platform
  1. Windows
Joe

There are various ways to get a filename depending on what exactly you want to do.

For example, you could allow the user to pick the file using Appplication.GetOpenFileName.

As for switch focus to copy/paste, well you should actually need to.

It's not normally needed to activate/select workbooks/sheets/ranges etc for that sort of thing.
 

Watch MrExcel Video

Forum statistics

Threads
1,113,919
Messages
5,545,027
Members
410,647
Latest member
bernardazar
Top