Solved

referencing a workbook VBA

Posted on 2014-07-22
2
170 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
2 Comments
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 250 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 21

Assisted Solution

by:Ejgil Hedegaard
Ejgil Hedegaard earned 250 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
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…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

828 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