LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default File name in macro

I failed to include in my original message that I'm trying to combine several
worksheets into one workbook and would like to use the macro to combine them
by referencing the file(s) as a generic name. I tried the ActiveWorkbook but
it doesn't work because the macro needs to access another workbook to
move/copy the other worksheet into my final workbook.

"Chip Pearson" wrote:

You can use the name of the ActiveWorkbook. The ActiveWorkbook is the
workbook that is currently visible and has focus in the Excel window.
E.g.,

Windows(ActiveWorkbook.Name).Activate

You can also use ThisWorkbook. ThisWorkbook always refers to the
workbook containing the presently running code, regardless of what
workbook might be active in Excel. E.g.,

Windows(ThisWorkbook.Name).Activate

You can also use the ordinal number of the workbook. E.g,

Windows(Workbooks(1).Name).Activate

I suppose you could prompt the user for a workbook number, with code
like the following:

Sub AAA()
Dim N As Long
Dim S As String
Dim WB As Workbook

S = "Select the number corresponding to the desired workbook." &
vbCrLf

For N = 1 To Workbooks.Count
S = S & CStr(N) & " " & Workbooks(N).Name & vbCrLf
Next N
N = Application.InputBox(prompt:=S, Title:="Select A Workbook",
Type:=1)
If N = 1 And N < Workbooks.Count Then
Set WB = Workbooks(N)
Windows(WB.Name).Activate
Else
MsgBox "Invalid Selection Number"
End If
End Sub

Beyond that, there isn't really a "generic" workbook.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Tue, 4 Nov 2008 15:18:01 -0800, Lizz45ie
wrote:

I recorded a macro using a file name but would like to be able to use the
macro with any workbook. What file name would I put in the macro so that the
macro looks for a generic file name and not a specific file name.

file name example in the macro:

Range("AK3").Select
Windows("OrderStatus9-29-08.xls").Activate


 
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
2007 Macro to Open File, Delete Contents, Save New File Flintstone[_2_] Excel Discussion (Misc queries) 2 February 1st 10 11:25 PM
Macro to call a file that has a auto open macro in the file itself [email protected] Excel Programming 1 August 5th 05 06:39 AM
Macro to insert values from a file and save another sheet as a .txt file Frank[_16_] Excel Programming 2 August 28th 03 01:07 AM
Automate open file, update links, run macro, close and save file Geoff[_7_] Excel Programming 2 August 26th 03 10:13 PM


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