Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Trouble setting variable as filename with date

Hi,
I'm trying to set a variable as a filename, and keep getting a compile
error "Object required." - it selects my variable "Newfilename =" when
this happens

Here's a snip:

Sub Namefile()
Const Dirpath As String = "C:\WINNT\Profiles\elby\Desktop\"
Dim newfilename As String

Set newfilename = Dirpath & format((Date - 1), "mmm-dd-yy") & "_Pres"
& ".xls"
End sub

I'm working in VBA - Excel 97, new at this.
Any ideas much appreciated!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Trouble setting variable as filename with date

Object variables require the Set statement. Regular variables can use
the optional Let statement (but almost nobody does). Instead:


Public Sub Namefile()
Const Dirpath As String = "C:\WINNT\Profiles\elby\Desktop\"
Dim newfilename As String

newfilename = Dirpath & Format((Date - 1), "mmm-dd-yy") & _
"_Pres.xls"
End Sub



In article ,
(Elby) wrote:

Hi,
I'm trying to set a variable as a filename, and keep getting a compile
error "Object required." - it selects my variable "Newfilename =" when
this happens

Here's a snip:

Sub Namefile()
Const Dirpath As String = "C:\WINNT\Profiles\elby\Desktop\"
Dim newfilename As String

Set newfilename = Dirpath & format((Date - 1), "mmm-dd-yy") & "_Pres"
& ".xls"
End sub

I'm working in VBA - Excel 97, new at this.
Any ideas much appreciated!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Trouble setting variable as filename with date

So simple, yet so much time I wasted trying to get that right! Thanks a
bunch - that's twice today you've helped me out (I also grabbed your
code from "Invalid use of null" - I've been trying to trim a range, and
this works!)



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
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
trouble setting colors feh Charts and Charting in Excel 3 July 10th 09 06:08 AM
set filename to <filename-date on open bob engler Excel Worksheet Functions 2 July 13th 06 05:11 AM
Put Filename Variable in Macro David Excel Discussion (Misc queries) 4 December 27th 05 06:27 PM
Global Setting For All Workbooks - Filename In Footer TOMB Excel Worksheet Functions 3 April 4th 05 06:53 PM
Trouble setting total for on chart Mark Charts and Charting in Excel 1 January 11th 05 02:21 AM


All times are GMT +1. The time now is 02:35 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"