Opening a workbook declared as a variable in VBA

jbenfleming

New Member
Joined
Mar 30, 2017
Messages
34
I am trying to open up a workbook that is declared as a variable. Is there a way to do this by using the variable name? I'd rather not have to use the long file path name. In the code after I move "blanksheet" from "dailysales" to "monthly" the dailysales workbook will no longer be open, as "blanksheet" was the only sheet in that workbook. After moving that sheet over I want to open the dailysales workbook again.

Code:
Option Explicit
Sub adailsalesend()
Dim rownum As Double
Dim dailysales As Workbook
Dim monthly As Workbook
Dim blanksheet As Worksheet


    Set dailysales = ActiveWorkbook
    Set blanksheet = ActiveSheet
    Workbooks.Open Filename:="filenamehere.xlsx"
    Set monthly = ActiveWorkbook


    dailysales.Activate
    Columns("k:k").Delete


    blanksheet.Move After:=monthly.Sheets(monthly.Sheets.Count)
'below this comment is where I want to open the "dailysales" book. The code does not work.
    Workbooks.Open (dailysales)


End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
For the record, It isn't a big deal for me to just use the filepath to open to workbook. I'm just curious if there is a way to use the variable name.
 
Upvote 0
Unless the folder the workbook is in is the active folder then you need the full path and name.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,853
Messages
6,127,334
Members
449,376
Latest member
karenmccabe

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top