Solved

referencing a workbook VBA

Posted on 2014-07-22
2
164 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 48

Accepted Solution

by:
Rgonzo1971 earned 250 total points
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

743 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

15 Experts available now in Live!

Get 1:1 Help Now