Consulting

Results 1 to 4 of 4

Thread: Solved: Reference another Excel workbook without Activating it

  1. #1
    VBAX Regular
    Joined
    Jun 2008
    Location
    Buderim, Queensland
    Posts
    54
    Location

    Solved: Reference another Excel workbook without Activating it

    Hi,

    I am running a command to convert some data in an Excel workbook to a new format. I would like to reference another Excel workbook while running the command. The only way I have been able to reference that data is by activating the other Excel workbook which I don't really want to do.....basically I would like only to have the initial workbook open and then read the data from the source workbook.

    [VBA]'Now lets Open the Source file to begin checking it is in the correct format
    Workbooks.Open(strSourceFullFileName).Activate
    Set mySourceRange = Worksheets("Sheet1").Range("A1")
    MsgBox "Have found this value at A1" & mySourceRange.Offset(0, 0).Value[/VBA]

    Is there anyway to reference that source workbook without activating it ?

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Set wb = Workbooks.Open(strSourceFullFileName)
    ...
    wb.Worksheets(1).Range("A1").Value = "something"
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jun 2008
    Location
    Buderim, Queensland
    Posts
    54
    Location
    Thanks got that referencing ok.....but with the open the active workbook still changes to the book that is referenced....is there a way to reference a workbook without having to open it and display it to the user ?

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Well, as you say, opening a workbook makes it active. But that should not be a problem if you use workbook variables for alal workbooks, and never refer to activeworkbook.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •