LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Cant get my code work. Find file or create it

In the Creat_MyFile sub I try to find a file called
2003.xls . If it exists it only opens it and creates a
new worksheet. If it does not exist it is created and a
new worksheet made.

I think my problem is that I am not using the right way
to find my file. Can you please help me out? I would
really appreciate it.

Thank you.

Private Sub CommandButton1_Click()
Dim MiMyDir As String
MiMyDir = "c:\Prices\"
If Dir(MiMyDir, vbDirectory) < "" Then
Create_MyFile MiMyDir
Else
MkDir MiMyDir
Create_MyFile MiMyDir
End If
End Sub

Sub Create_MyFile(MyDir As String)
Dim MiMyFile As String
Dim MyDate, MyYear
MyDate = Now
MiMyFile = Year(MyDate) & ".xls"
If Dir(MiMyFile, vbDirectory) < "" Then
Open_MyFile
Else
Application.Workbooks.Add
ActiveWorkbook.SaveAs MyDir & MiMyFile
ActiveWorkbook.Close
Open_MyFile
End If
End Sub
Sub Open_MyFile()
Dim MyDate
MyDate = Now
Application.Workbooks.Open ("C:\Prices\" & Year
(MyDate) & ".xls")
Dim ShName As String
Dim nChr As Integer
ShName = CStr(Date)
' Replace /
For nChr = 1 To Len(ShName)
If Mid(ShName, nChr, 1) = "/" Then Mid(ShName,
nChr, 1) = "-"
Next
Worksheets.Add(After:=Worksheets
(Worksheets.Count)).Name = ShName
End Sub

 
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
Code to create dbase file from text file? Hilton Excel Discussion (Misc queries) 0 October 9th 08 10:37 AM
Why does this code not work? rk0909 Excel Discussion (Misc queries) 12 September 4th 08 10:42 PM
HOW DO I FIND A FILE WHEN SHORTCUT DOES NOT WORK pat Excel Discussion (Misc queries) 1 August 2nd 07 06:16 PM
How to create a form to insert a hyerlink.VBA code to create a for karthi Excel Discussion (Misc queries) 0 July 5th 06 11:26 AM
Code does not work on emailed file EFWY Excel Discussion (Misc queries) 3 October 24th 05 02:52 PM


All times are GMT +1. The time now is 07:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"