PDA

View Full Version : [SOLVED] Plz help, Macro needed for If the file opened from folder, do this



loveguy1977
09-04-2013, 07:35 AM
Dear All,

I need your help. I need to write a macro in the [Sub Workbook_Open()] with if statement stating that if this file opened from folder (C:/Test), then do this.
If the file opened from other folder, don't do any thing

Thank you very much

patel
09-04-2013, 08:13 AM
can you explain better your goal ?

loveguy1977
09-04-2013, 09:22 AM
Say there is file (called love.xlsm) saved in folder c:/teat. The same file open (love.xlsm) copied to another folder. So if the file love.xlsm opened from folder c:/test, run macro (say clear cell A1 text). but if opened from another folder don't clear A1 text

Kenneth Hobs
09-04-2013, 09:40 AM
If lCase(ThisWorkbook.Path) = "c:\test" then ...

loveguy1977
09-04-2013, 10:12 AM
If lCase(ThisWorkbook.Path) = "c:\test" then ...

Sorry it is not working for any of bellow. I did the following:


Private Sub Workbook_Open()
If LCase(ThisWorkbook.Path) = "C:\Test" Then
Sheets("Sheet1").Select
Selection.ClearContents
Else
Exit Sub
End If
End Sub

or



Private Sub Workbook_Open()
If ThisWorkbook.Path = "C:\Test" Then
Sheets("Sheet1").Select
Selection.ClearContents
Else
Exit Sub
End If
End Sub

loveguy1977
09-04-2013, 01:08 PM
Sorry guys
I found my mistake
it should be like this


Private Sub Workbook_Open()
If ThisWorkbook.Path = "C:\Test" Then
Sheets("Sheet1").Select
Range("A1").Select
Selection.ClearContents
End If
End Sub

Kenneth Hobs
09-04-2013, 01:17 PM
Private Sub Workbook_Open()
If ThisWorkbook.Path = "C:\Test" Then Sheets("Sheet1").Range("A1").ClearContents
End Sub