Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 234
Default Error when running macro

Hi,

I have the following code that runs fine when the file is opened from my
directory, however when opened from a file attached to an email, a code 9
error occurs. I think it's to do with the file name when opened from an
email being ~7341470.xls (or similar) whereas it has a proper name when
opened from a directory. Is there a way to overcome this, perhaps by
checking whether the file has ~ in its name?

Dim iFname As String
Range("A1").Formula = _
"=VLOOKUP(D2,[" + iFname + "]Database,2,False)"

Thanks, Rob


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Error when running macro

difficult to guess, without knowing what's in iFname.

But did you include the exclamation point?

And did you include the single quotes around the filename?

And if the Database is in the same workbook, you could drop all that stuff that
refers to another workbook.

And VBA is very forgiving, but I'd use & to concatenate strings.
+ is usually used for adding numbers.





Rob wrote:

Hi,

I have the following code that runs fine when the file is opened from my
directory, however when opened from a file attached to an email, a code 9
error occurs. I think it's to do with the file name when opened from an
email being ~7341470.xls (or similar) whereas it has a proper name when
opened from a directory. Is there a way to overcome this, perhaps by
checking whether the file has ~ in its name?

Dim iFname As String
Range("A1").Formula = _
"=VLOOKUP(D2,[" + iFname + "]Database,2,False)"

Thanks, Rob


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
Rob Rob is offline
external usenet poster
 
Posts: 234
Default Error when running macro

Thanks Dave, single quotes was the problem. Rob

"Dave Peterson" wrote in message
...
difficult to guess, without knowing what's in iFname.

But did you include the exclamation point?

And did you include the single quotes around the filename?

And if the Database is in the same workbook, you could drop all that stuff
that
refers to another workbook.

And VBA is very forgiving, but I'd use & to concatenate strings.
+ is usually used for adding numbers.





Rob wrote:

Hi,

I have the following code that runs fine when the file is opened from my
directory, however when opened from a file attached to an email, a code 9
error occurs. I think it's to do with the file name when opened from an
email being ~7341470.xls (or similar) whereas it has a proper name when
opened from a directory. Is there a way to overcome this, perhaps by
checking whether the file has ~ in its name?

Dim iFname As String
Range("A1").Formula = _
"=VLOOKUP(D2,[" + iFname + "]Database,2,False)"

Thanks, Rob


--

Dave Peterson



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
Error 400 when running Macro Jim@Tech Excel Discussion (Misc queries) 3 October 20th 08 05:35 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Worksheet Functions 1 May 3rd 08 02:35 PM
I tried to get around the problem of the pivot table field settingdefaulting to Count instead of Sum by running a macro of change the settingfrom Count to Sum. However, when I tried to run the Macro, I got error messageof run time error 1004, unable Enda80 Excel Discussion (Misc queries) 1 May 3rd 08 10:52 AM
error when running cut & paste macro Otto Moehrbach Excel Worksheet Functions 4 August 9th 06 01:49 PM
Error Running a Macro viddom Excel Discussion (Misc queries) 3 July 28th 05 01:56 PM


All times are GMT +1. The time now is 12:50 AM.

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"