PDA

View Full Version : Solved: [solved] Help with Email active worksheet example



Loranga
02-05-2007, 08:07 AM
Aloha,
I've used the
Email active worksheet using Outlook
example from this site. since it's my first post I cant post the link.
Now my question:
Is it possbible to get this code

FileName = "Temp.xls" to take a value from the woorksheet lets say from the cell B2. If the user types "June" in B2 then the file will be named June.xls?

Bob Phillips
02-05-2007, 08:18 AM
Filename = Range("B2").value & ".xls"


but I would advise agaianst using Filename as variable.

Loranga
02-05-2007, 08:32 AM
Thanks for your help, you are probably right about using Filename as variable.

I've tried to solve it with this code


If Range("B3") = "" Then
FileName = "Empty.xls"
Else
FileName = Range("B3").Value & ".xls"
End If

Bob Phillips
02-05-2007, 08:44 AM
And what is the problem?

Loranga
02-05-2007, 08:49 AM
No problem at the moment, its working fine for me. But I was thinking of your comment that it isn't a good idea to "using Filename as variable".
With my new code it works even if the user leave B3 blank. I't probably not the right way to do it but it's working ;)

lucas
02-05-2007, 08:53 AM
I think that Bob is trying to say that using the word "Filename" as a variable would not be advisable as it is a property in VBA. If you changed it to FName or something else when using it as a variable then it wouldn't be an issue....is that about right Bob?

Bob Phillips
02-05-2007, 09:11 AM
I think that Bob is trying to say that using the word "Filename" as a variable would not be advisable as it is a property in VBA. If you changed it to FName or something else when using it as a variable then it wouldn't be an issue....is that about right Bob?
Sorry, I interpreted your comment of ... I tried ... as meaning it was still giving you a problem.

Steve is spot on. Even if you don't get a problem with it today, a future version might apply tighter syntax rules, part of what I call defensive programming.

lucas
02-05-2007, 09:23 AM
Just to follow up and be sure Loranga understands....
Filename used as Ken used it in the kb is not a variable.


FileName = "Temp.xls"

But when you changed the usage to a variable based on a cell value depending on the active sheet then it becomes an issue.