PC Review


Reply
Thread Tools Rate Thread

Put Filename Variable in Macro

 
 
=?Utf-8?B?RGF2aWQ=?=
Guest
Posts: n/a
 
      27th Dec 2005
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)

 
Reply With Quote
 
 
 
 
Norman Jones
Guest
Posts: n/a
 
      27th Dec 2005
Hi David,

Try changing:

> Set wbSum = FName


to:

Set wbSum = Workbooks(FName)


---
Regards,
Norman



"David" <(E-Mail Removed)> wrote in message
news:27AA7DEA-EFC6-44AA-8BF7-(E-Mail Removed)...
>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)
>



 
Reply With Quote
 
 
 
 
vezerid
Guest
Posts: n/a
 
      27th Dec 2005
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

 
Reply With Quote
 
Andrew Taylor
Guest
Posts: n/a
 
      27th Dec 2005
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)


 
Reply With Quote
 
Dave O
Guest
Posts: n/a
 
      27th Dec 2005
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
HttpPostedFile.saveas(filename) issue when the filename is used "-" as a part of the filename. Ken Microsoft Dot NET Framework 0 25th Feb 2009 11:58 PM
Converting a Variable Filename to a Constant Filename =?Utf-8?B?TWFnbml2eQ==?= Microsoft Excel Programming 2 15th Aug 2006 06:13 PM
Show files in datagrid (DirectoryInfo), make button to choose a file and put the filename in a session-variable Øyvind Isaksen Microsoft ASP .NET 3 12th Feb 2006 12:43 AM
Put Filename Variable in Macro =?Utf-8?B?RGF2aWQ=?= Microsoft Excel Programming 1 27th Dec 2005 04:00 AM
Need macro to open a variable filename =?Utf-8?B?U3RldmVAQUJT?= Microsoft Excel Programming 5 2nd Jun 2005 09:08 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:25 PM.