Consulting

Results 1 to 8 of 8

Thread: Solved: [solved] Help with Email active worksheet example

  1. #1
    VBAX Newbie
    Joined
    Feb 2007
    Posts
    4
    Location

    Solved: [solved] Help with Email active worksheet example

    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?
    Last edited by Loranga; 02-06-2007 at 12:12 AM.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]
    Filename = Range("B2").value & ".xls"
    [/vba]

    but I would advise agaianst using Filename as variable.

  3. #3
    VBAX Newbie
    Joined
    Feb 2007
    Posts
    4
    Location
    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

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    And what is the problem?

  5. #5
    VBAX Newbie
    Joined
    Feb 2007
    Posts
    4
    Location
    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

  6. #6
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    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?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by lucas
    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.

  8. #8
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Just to follow up and be sure Loranga understands....
    Filename used as Ken used it in the kb is not a variable.
    [VBA]
    FileName = "Temp.xls"
    [/VBA]
    But when you changed the usage to a variable based on a cell value depending on the active sheet then it becomes an issue.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •