Editting Macro

Nishant79

New Member
Joined
Jun 2, 2011
Messages
28
Hi there

I have this macro and in one of it there is this line in it where i have to change the date daily (02JUN),its a path where some data is saved each day,So is there anything that the excel always updates the date of today without me changing it.


Workbooks.Open Filename:= _
"Z:\Tom\GETS_FILES\GETS_EXCEL\02Jun\NetPosition.xls"

So can anyone help????
 
if i am getting you correctly then your asking me is it my file name ????

yes if its the name of my excel .....NestXL-NishantNew i save it as this name.
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try this:
Code:
Sub day1()
    Dim strDate As String
    Dim strFile As String
    Dim blnProceed As Boolean
    Dim wkbNetPos As Workbook
    
    strDate = Format$(Sheets("Final").Range("A2").Value2, "ddmmm")
    strFile = "Z:\Tom\GETS_FILES\GETS_EXCEL\" & strDate & "\NetPosition.xls"

    blnProceed = CBool(Len(Dir$(strFile)) > 0) 'use a boolean to hold whether or not the file exists
    
    If Not blnProceed Then
    'it doesn't exist, so warn the user
        MsgBox Prompt:="The following file or file directory does not exist:" & vbCrLf & _
                       strFile, _
               Buttons:=vbExclamation + vbOKCancel
    Else
    'it does exist, so run the code
        Set wkbNetPos = Workbooks.Open(Filename:=strFile, UpdateLinks:=False)
        With wkbNetPos
            .Sheets(1).Range("A1:Q499").Copy Destination:=ThisWorkbook.Sheets("Copy Sheet").Range("A1")
            Application.CutCopyMode = False
            .Close SaveChanges:=False
        End With
    End With
End Sub
 
Upvote 0
See correction in red, looks like a typo!
Rich (BB code):
Sub day1()
    Dim strDate As String
    Dim strFile As String
    Dim blnProceed As Boolean
    Dim wkbNetPos As Workbook
 
    strDate = Format$(Sheets("Final").Range("A2").Value2, "ddmmm")
    strFile = "Z:\Tom\GETS_FILES\GETS_EXCEL\" & strDate & "\NetPosition.xls"
 
    blnProceed = CBool(Len(Dir$(strFile)) > 0) 'use a boolean to hold whether or not the file exists
 
    If Not blnProceed Then
    'it doesn't exist, so warn the user
        MsgBox Prompt:="The following file or file directory does not exist:" & vbCrLf & _
                       strFile, _
               Buttons:=vbExclamation + vbOKCancel
    Else
    'it does exist, so run the code
        Set wkbNetPos = Workbooks.Open(Filename:=strFile, UpdateLinks:=False)
        With wkbNetPos
            .Sheets(1).Range("A1:Q499").Copy Destination:=ThisWorkbook.Sheets("Copy Sheet").Range("A1")
            Application.CutCopyMode = False
            .Close SaveChanges:=False
        End With
    End IF
End Sub

(Tut tut Jon, too many shandy's... big girl's blouse!)
 
Upvote 0
Thanks it works perfectly thanks to everyone and jon who has helped me from the start i really feel great to join this forum :)

thanks to all
 
Upvote 0

Forum statistics

Threads
1,224,505
Messages
6,179,152
Members
452,891
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top