Solved

referencing a workbook VBA

Posted on 2014-07-22
2
165 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 49

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now