Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Sep 2001
    Location
    Stuck at work..., Missouri, USA
    Posts
    248
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA - Excel forumla referencing a different workbo

    I have an Access app that builds excel workbooks. In 1 I have a cell that needs to reference a cell in another workbook on my hard drive.

    I have the formula built like this:

    ='[WorkbookName.xls]SheetName'!$A$1

    the formula works, but when stepping thru the code, as soon as it does this line:
    xlapp.ActiveCell.Value = "='[WorkbookName.xls]SheetName'!$A$1"

    Excel open the Open File dialog.

    Not good for automating.

    Is there a way around this?
    <font face="Comic Sans MS">Morgan Erickson</font face=comic>
    morgan.erickson@sprint.com
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18>-From <img src=/S/flags/Colorado.gif border=0 alt=Colorado width=30 height=18> but living in <img src=/S/flags/Missouri.gif border=0 alt=Missouri width=30 height=18>...and working in Kansas.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VBA - Excel forumla referencing a different workbo

    If the other workbook is not open, you should specify the full path:
    <code>
    xlapp.ActiveCell.Value = "='C:MyFolder[WorkbookName.xls]SheetName'!$A$1"
    </code>
    You must, of course, substitute the actual path. Otherwise Excel cannot resolve the external reference.

  3. #3
    3 Star Lounger
    Join Date
    Sep 2001
    Location
    Stuck at work..., Missouri, USA
    Posts
    248
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA - Excel forumla referencing a different wo

    Hans,

    If I could hug you right now I would.

    Consider yourself hugged!!
    <font face="Comic Sans MS">Morgan Erickson</font face=comic>
    morgan.erickson@sprint.com
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18>-From <img src=/S/flags/Colorado.gif border=0 alt=Colorado width=30 height=18> but living in <img src=/S/flags/Missouri.gif border=0 alt=Missouri width=30 height=18>...and working in Kansas.

  4. #4
    3 Star Lounger
    Join Date
    Sep 2001
    Location
    Stuck at work..., Missouri, USA
    Posts
    248
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA - Excel forumla referencing a different wo

    Is it possible to have that cell = the VALUE rather than be linked?
    <font face="Comic Sans MS">Morgan Erickson</font face=comic>
    morgan.erickson@sprint.com
    <img src=/S/flags/USA.gif border=0 alt=USA width=30 height=18>-From <img src=/S/flags/Colorado.gif border=0 alt=Colorado width=30 height=18> but living in <img src=/S/flags/Missouri.gif border=0 alt=Missouri width=30 height=18>...and working in Kansas.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VBA - Excel forumla referencing a different wo

    You could try this:
    <code>
    With xlapp.ActiveCell
    .Value = "='C:MyFolder[WorkbookName.xls]SheetName'!$A$1"
    .Value = .Value
    End With</code>

Posting Permissions

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