Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Can anyone help with the code to first identify a drive letter on PC which
may also be different to the one on the PC that the macro was built on. I need to save a file to a specific folder path and if the drive letter is different how to specify a folder path. I hope that makes sense? -- Kind Regards Mick |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
What information do you have to start with? How would we know we have the
right drive? Do you want to search all drives for a particular folder? -- Regards, Tom Ogilvy "Grandad" wrote in message ... Can anyone help with the code to first identify a drive letter on PC which may also be different to the one on the PC that the macro was built on. I need to save a file to a specific folder path and if the drive letter is different how to specify a folder path. I hope that makes sense? -- Kind Regards Mick |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If you have a path string:
Sub findDrive() Dim fs As Object, f As Object Dim sPath As String, drv As Object Dim sPath1 As String sPath = "Data\CSVDaily" Set fs = CreateObject("Scripting.FileSystemObject") For Each drv In fs.Drives sPath1 = drv.DriveLetter & ":\" & sPath On Error Resume Next Set f = Nothing Set f = fs.GetFolder(sPath1) On Error GoTo 0 If Not f Is Nothing Then MsgBox "found in drive " & drv.DriveLetter End If Next End Sub -- Regards, Tom Ogilvy "Tom Ogilvy" wrote in message ... What information do you have to start with? How would we know we have the right drive? Do you want to search all drives for a particular folder? -- Regards, Tom Ogilvy "Grandad" wrote in message ... Can anyone help with the code to first identify a drive letter on PC which may also be different to the one on the PC that the macro was built on. I need to save a file to a specific folder path and if the drive letter is different how to specify a folder path. I hope that makes sense? -- Kind Regards Mick |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Tom
I'm sorry if I've not been clear. I guess what I need is to be able to identify the default drive letter for each PC the macro is used on and to have a folder path to save a file that works on all PCs. I hope that's a bit better tan my first attempt? Mick "Tom Ogilvy" wrote in message ... If you have a path string: Sub findDrive() Dim fs As Object, f As Object Dim sPath As String, drv As Object Dim sPath1 As String sPath = "Data\CSVDaily" Set fs = CreateObject("Scripting.FileSystemObject") For Each drv In fs.Drives sPath1 = drv.DriveLetter & ":\" & sPath On Error Resume Next Set f = Nothing Set f = fs.GetFolder(sPath1) On Error GoTo 0 If Not f Is Nothing Then MsgBox "found in drive " & drv.DriveLetter End If Next End Sub -- Regards, Tom Ogilvy "Tom Ogilvy" wrote in message ... What information do you have to start with? How would we know we have the right drive? Do you want to search all drives for a particular folder? -- Regards, Tom Ogilvy "Grandad" wrote in message ... Can anyone help with the code to first identify a drive letter on PC which may also be different to the one on the PC that the macro was built on. I need to save a file to a specific folder path and if the drive letter is different how to specify a folder path. I hope that makes sense? -- Kind Regards Mick |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Dim sDrive as String
sDrive = left(curdir,1) on error resume next mkdir sDrive & ":\MyMacroFolder" On error goto 0 Application.displayalerts = False ThisWorkbook.SaveAs sDrive & ":\MyMacroFolder\" & thisworkbook.Name Application.DisplayAlerts = True -- Regards, Tom Ogilvy "Grandad" wrote in message ... Tom I'm sorry if I've not been clear. I guess what I need is to be able to identify the default drive letter for each PC the macro is used on and to have a folder path to save a file that works on all PCs. I hope that's a bit better tan my first attempt? Mick "Tom Ogilvy" wrote in message ... If you have a path string: Sub findDrive() Dim fs As Object, f As Object Dim sPath As String, drv As Object Dim sPath1 As String sPath = "Data\CSVDaily" Set fs = CreateObject("Scripting.FileSystemObject") For Each drv In fs.Drives sPath1 = drv.DriveLetter & ":\" & sPath On Error Resume Next Set f = Nothing Set f = fs.GetFolder(sPath1) On Error GoTo 0 If Not f Is Nothing Then MsgBox "found in drive " & drv.DriveLetter End If Next End Sub -- Regards, Tom Ogilvy "Tom Ogilvy" wrote in message ... What information do you have to start with? How would we know we have the right drive? Do you want to search all drives for a particular folder? -- Regards, Tom Ogilvy "Grandad" wrote in message ... Can anyone help with the code to first identify a drive letter on PC which may also be different to the one on the PC that the macro was built on. I need to save a file to a specific folder path and if the drive letter is different how to specify a folder path. I hope that makes sense? -- Kind Regards Mick |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks Tom I'll try that,
I know how to move forward in a folder structure, but how do to go back? Thanks again Mick "Tom Ogilvy" wrote in message ... Dim sDrive as String sDrive = left(curdir,1) on error resume next mkdir sDrive & ":\MyMacroFolder" On error goto 0 Application.displayalerts = False ThisWorkbook.SaveAs sDrive & ":\MyMacroFolder\" & thisworkbook.Name Application.DisplayAlerts = True -- Regards, Tom Ogilvy "Grandad" wrote in message ... Tom I'm sorry if I've not been clear. I guess what I need is to be able to identify the default drive letter for each PC the macro is used on and to have a folder path to save a file that works on all PCs. I hope that's a bit better tan my first attempt? Mick "Tom Ogilvy" wrote in message ... If you have a path string: Sub findDrive() Dim fs As Object, f As Object Dim sPath As String, drv As Object Dim sPath1 As String sPath = "Data\CSVDaily" Set fs = CreateObject("Scripting.FileSystemObject") For Each drv In fs.Drives sPath1 = drv.DriveLetter & ":\" & sPath On Error Resume Next Set f = Nothing Set f = fs.GetFolder(sPath1) On Error GoTo 0 If Not f Is Nothing Then MsgBox "found in drive " & drv.DriveLetter End If Next End Sub -- Regards, Tom Ogilvy "Tom Ogilvy" wrote in message ... What information do you have to start with? How would we know we have the right drive? Do you want to search all drives for a particular folder? -- Regards, Tom Ogilvy "Grandad" wrote in message ... Can anyone help with the code to first identify a drive letter on PC which may also be different to the one on the PC that the macro was built on. I need to save a file to a specific folder path and if the drive letter is different how to specify a folder path. I hope that makes sense? -- Kind Regards Mick |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Tom it's working more or less as I need it too so thanks for your help.
Having created the new folder is there a way to go back or identify the original drive we started from? Regards Mick "Tom Ogilvy" wrote in message ... Dim sDrive as String sDrive = left(curdir,1) on error resume next mkdir sDrive & ":\MyMacroFolder" On error goto 0 Application.displayalerts = False ThisWorkbook.SaveAs sDrive & ":\MyMacroFolder\" & thisworkbook.Name Application.DisplayAlerts = True -- Regards, Tom Ogilvy "Grandad" wrote in message ... Tom I'm sorry if I've not been clear. I guess what I need is to be able to identify the default drive letter for each PC the macro is used on and to have a folder path to save a file that works on all PCs. I hope that's a bit better tan my first attempt? Mick "Tom Ogilvy" wrote in message ... If you have a path string: Sub findDrive() Dim fs As Object, f As Object Dim sPath As String, drv As Object Dim sPath1 As String sPath = "Data\CSVDaily" Set fs = CreateObject("Scripting.FileSystemObject") For Each drv In fs.Drives sPath1 = drv.DriveLetter & ":\" & sPath On Error Resume Next Set f = Nothing Set f = fs.GetFolder(sPath1) On Error GoTo 0 If Not f Is Nothing Then MsgBox "found in drive " & drv.DriveLetter End If Next End Sub -- Regards, Tom Ogilvy "Tom Ogilvy" wrote in message ... What information do you have to start with? How would we know we have the right drive? Do you want to search all drives for a particular folder? -- Regards, Tom Ogilvy "Grandad" wrote in message ... Can anyone help with the code to first identify a drive letter on PC which may also be different to the one on the PC that the macro was built on. I need to save a file to a specific folder path and if the drive letter is different how to specify a folder path. I hope that makes sense? -- Kind Regards Mick |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Obtain drive letter assignment of CD/DVD drive? | Excel Discussion (Misc queries) | |||
Can I show server name instead of drive letter? | Excel Discussion (Misc queries) | |||
Using path instead of drive letter | Excel Programming | |||
Drive Letter of current file | Excel Programming | |||
How to find the drive letter? | Excel Programming |