• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

'Object Required' error message

PipBoy808

Member
Sub ImportFromMaster()
Dim MasterSource As Workbook, DSVTarget As Workbook
Dim WeekNum As String
Dim filepath As String
Dim truckfilename As String

Set DSVTarget = ActiveWorkbook

Set filepath = Worksheets("Reference").Range("G3").Value
Set truckfilename = Worksheets("Reference").Range("G4").Value

MasterSource = filepath & truckfilename
MsgBox MasterSource
==========================================
Hello! The above code is the start of a macro I'm working on. I'm trying to compile the variable 'MasterSource' from cells G3 and G4 in a worksheet named "Reference". I want to temporarily generate a MsgBox to be sure that I've compiled Mastersource correctly. However, the red text indicates where Excel keeps returning the error message:

"Compile error: Object Required"

Can anyone tell me what I'm doing wrong?
 
Strings do not get "set", as it's not an object. :)

This will work for you.
filepath = Worksheets("Reference").Range("G3").Value
truckfilename = Worksheets("Reference").Range("G4").Value

So, to try and understand the error, the Set was telling VB to make some object equal to a value, but you were giving it a string, not an object. Thus, it's objection and reason why it was asking for one.
 
Back
Top