Error when running macro

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

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
 
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.




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
 
Thanks Dave, single quotes was the problem. Rob

Dave Peterson said:
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.




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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top