Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50163

Help with variables

$
0
0
I'm trying to merge two macros. the first I found here, the second I recorded. The first section has variables assigned, while the second uses file names. I want to get rid of the file names and think I probably need to so before the copying bit, but everything I tried errors.

In the end, this should be run from the Top10 file, prompt to open the Master file, copy the master sheet inside the Master file to a new sheet in Top10, and close the Master file. After this, I have a bunch more to run, but this is the first step (and it's broken, sigh).

Thanks.

Code:

Sub master_to_top10()
' Get Master workbook...
Dim MasterBook As Workbook
Dim filter As String
Dim caption As String
Dim MasterFilename As String
Dim MasterWorkbook As Workbook
Dim targetWorkbook As Workbook

' make weak assumption that active workbook is the target
Set targetWorkbook = Application.ActiveWorkbook

' get the Master workbook
filter = "Text files (*.xlsx),*.xlsx"
MsgBox ("Please Select the Master File")
caption = "Please Select the Master File"
MasterFilename = Application.GetOpenFilename(filter, , caption)

Set MasterWorkbook = Application.Workbooks.Open(MasterFilename)

' --------------------------------------------------------------------------------
' ----------------Here's where I need to be back to variables-----------------------
' --------------------------------------------------------------------------------
    Windows("Master to F.xlsx").Activate
    Sheets("Master").Select
    Sheets("Master").Move Before:=Workbooks("Top10 to F.xlsm").Sheets(2)

' --------------------------------------------------------------------------------
' ----------------Error here should be closing by variable---------------------------
' --------------------------------------------------------------------------------
' Close Master workbook
"Master to F.xlsx".Close
End Sub


Viewing all articles
Browse latest Browse all 50163

Trending Articles