?
Solved

referencing a workbook VBA

Posted on 2014-07-22
2
Medium Priority
?
179 Views
Last Modified: 2014-07-23
I have a module


Sub RunTheReport()

Dim Repfile As Workbook
Set Repfile = ThisWorkbook

Application.ScreenUpdating = False

Call XYZ

End Sub

with in XYZ, I have a line of code saying

RepFile.activate

I am getting the "object Required" error

Where am i going wrong?

Thanks
0
Comment
Question by:Seamus2626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 1000 total points
ID: 40211917
Hi,

You have to refer to the file in the sub

Sub RunTheReport()
Dim Repfile As Workbook
   Set Repfile = ThisWorkbook
   Application.ScreenUpdating = False
   Call XYZ(Repfile)
End Sub

Sub XYZ(myFile)
   myFile.Activate
End Sub

Open in new window



O ryou have to put
Dim Repfile As Workbook
at the beginning of your module out of any sub or function
as global variable

Regards
0
 
LVL 23

Assisted Solution

by:Ejgil Hedegaard
Ejgil Hedegaard earned 1000 total points
ID: 40211926
Move
Dim Repfile As Workbook
above all subs in the module, and change to
Public Repfile As Workbook

Now Repfile is only to use in RunTheReport, not in other subs.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question