Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
David
 
Posts: n/a
Default Put Filename Variable in Macro

I have a macro that stores the full path/filename of a file that is needed in
another macro to cell B8 on a sheet named Index. This sets the file location
which can vary by location.
Another macro uses this file to post data to from the current workbook. I'm
having trouble getting the macro to use the filename variable stored in cell
B8.
Can you help? Here is the code that's in question:

Dim wbSum As Workbook, wbData As Workbook
Dim sht
Dim FName As Variant
FName = Worksheets("Index").Range("B8")
Set wbSum = FName <==Here's the problem line!
Set wbData = ActiveWorkbook
Dim iDate As Date, iValue
Dim lastcol As Long, xV As Long, xR As Long, xC As Long
Workbooks.Open (Filename)

  #2   Report Post  
Posted to microsoft.public.excel.misc
Norman Jones
 
Posts: n/a
Default Put Filename Variable in Macro

Hi David,

Try changing:

Set wbSum = FName


to:

Set wbSum = Workbooks(FName)


---
Regards,
Norman



"David" wrote in message
...
I have a macro that stores the full path/filename of a file that is needed
in
another macro to cell B8 on a sheet named Index. This sets the file
location
which can vary by location.
Another macro uses this file to post data to from the current workbook.
I'm
having trouble getting the macro to use the filename variable stored in
cell
B8.
Can you help? Here is the code that's in question:

Dim wbSum As Workbook, wbData As Workbook
Dim sht
Dim FName As Variant
FName = Worksheets("Index").Range("B8")
Set wbSum = FName <==Here's the problem line!
Set wbData = ActiveWorkbook
Dim iDate As Date, iValue
Dim lastcol As Long, xV As Long, xR As Long, xC As Long
Workbooks.Open (Filename)



  #3   Report Post  
Posted to microsoft.public.excel.misc
vezerid
 
Posts: n/a
Default Put Filename Variable in Macro

David,
The Set statement makes assignments to objects. Youf FName variable is
not an object. The method you are seeking is the Open method of the
Workbooks Collection object. Replace with:
Workbooks.Open(FName)

When opened it becomes the ActiveWorkbook so the following line should
be fine if you mean to work with the recently opened file.

HTH
Kostis Vezerides

  #4   Report Post  
Posted to microsoft.public.excel.misc
Andrew Taylor
 
Posts: n/a
Default Put Filename Variable in Macro

Instead of
Set wbSum = FName
you need
Set wbSum = Workbooks.Open (FName)

Also, the line
Workbooks.Open (Filename)
seems wrong, as you haven't declared or initialised Filename
(typo for FName?). You _are_ using Option Explicit, aren't you...?

Andrew Taylor


David wrote:
I have a macro that stores the full path/filename of a file that is needed in
another macro to cell B8 on a sheet named Index. This sets the file location
which can vary by location.
Another macro uses this file to post data to from the current workbook. I'm
having trouble getting the macro to use the filename variable stored in cell
B8.
Can you help? Here is the code that's in question:

Dim wbSum As Workbook, wbData As Workbook
Dim sht
Dim FName As Variant
FName = Worksheets("Index").Range("B8")
Set wbSum = FName <==Here's the problem line!
Set wbData = ActiveWorkbook
Dim iDate As Date, iValue
Dim lastcol As Long, xV As Long, xR As Long, xC As Long
Workbooks.Open (Filename)


  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave O
 
Posts: n/a
Default Put Filename Variable in Macro

Try changing this line
FName = Worksheets("Index").Range("B8")

to this:
FName = Worksheets("Index").Range("B8").Value

As a test you can add this line and run the code before and after the
suggested change:
FName = Worksheets("Index").Range("B8")
Msgbox FName

You should see the expected results.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Range used in a macro needs to be variable DaveP Excel Worksheet Functions 3 November 4th 05 03:23 PM
Closing File Error jcliquidtension Excel Discussion (Misc queries) 4 October 20th 05 12:22 PM
Forcing a macro to pause for filename matpoh Excel Discussion (Misc queries) 3 September 13th 05 06:28 PM
open file (as variable) from macro d chaps Excel Discussion (Misc queries) 1 March 14th 05 11:57 PM
Help with macro formula and variable Huge project Excel Worksheet Functions 0 December 28th 04 01:27 AM


All times are GMT +1. The time now is 08:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"