Tony Williams
New Member
- Joined
- Mar 5, 2008
- Messages
- 7
I am trying to save a file to 3 different folders on two different computers.
The file path depends on which computer I am doing the save operation.
I am trying to loop on a file path variable and the variable doesn't return the file path.
Also, the ActiveWorkbook.SaveAs function doesn't work either.
Sub SaveToLocations()
'Store the opened file name:
Dim OrigName As String
Dim i As Integer
Dim currentFolder As String
Dim compName As String
Dim folderHP1 As String
Dim folderHP2 As String
Dim folderHP3 As String
Dim folderTP1 As String
Dim folderTP2 As String
Dim folderTP3 As String
OrigName = ActiveWorkbook.FullName
i = 1
currentFolder = " "
compName = " "
folderHP1 = "My Passport"
folderHP2 = "\\Thinkpad X220\Users\skyzzx"
folderHP3 = "C:\Users\User\Documents"
folderTP1 = Dir("\\HP\Users\User\Documents")
folderTP2 = "\\HP\My Passport"
folderTP3 = "C:\Users\skyzz\Documents"
' Turn off screen updating:
Application.DisplayAlerts = False
If FileFolderExists("C:\Users\User\Documents") Then
compName = "HP"
End If
If FileFolderExists("C:\Users\skyzz\Documents") Then
compName = "TP"
End If
Do
currentFolder = "folder" & compName & i
If FileFolderExists(Dir(currentFolder)) Then
ActiveWorkbook.SaveAs Dir("folder" & compName & i) & ActiveWorkbook.Name
MsgBox "My file saved."
Else
MsgBox "My file does not exist!"
End If
i = i + 1
Loop Until i = 4
' Turn on screen updating:
Application.DisplayAlerts = True
End Sub
Public Function FileFolderExists(strFullPath As String) As Boolean
'Author : Ken Puls (www.excelguru.ca)
'Macro Purpose: Check if a file or folder exists
On Error GoTo EarlyExit
If Not Dir(strFullPath, vbDirectory) = vbNullString Then FileFolderExists = True
EarlyExit:
On Error GoTo 0
End Function
The file path depends on which computer I am doing the save operation.
I am trying to loop on a file path variable and the variable doesn't return the file path.
Also, the ActiveWorkbook.SaveAs function doesn't work either.
Sub SaveToLocations()
'Store the opened file name:
Dim OrigName As String
Dim i As Integer
Dim currentFolder As String
Dim compName As String
Dim folderHP1 As String
Dim folderHP2 As String
Dim folderHP3 As String
Dim folderTP1 As String
Dim folderTP2 As String
Dim folderTP3 As String
OrigName = ActiveWorkbook.FullName
i = 1
currentFolder = " "
compName = " "
folderHP1 = "My Passport"
folderHP2 = "\\Thinkpad X220\Users\skyzzx"
folderHP3 = "C:\Users\User\Documents"
folderTP1 = Dir("\\HP\Users\User\Documents")
folderTP2 = "\\HP\My Passport"
folderTP3 = "C:\Users\skyzz\Documents"
' Turn off screen updating:
Application.DisplayAlerts = False
If FileFolderExists("C:\Users\User\Documents") Then
compName = "HP"
End If
If FileFolderExists("C:\Users\skyzz\Documents") Then
compName = "TP"
End If
Do
currentFolder = "folder" & compName & i
If FileFolderExists(Dir(currentFolder)) Then
ActiveWorkbook.SaveAs Dir("folder" & compName & i) & ActiveWorkbook.Name
MsgBox "My file saved."
Else
MsgBox "My file does not exist!"
End If
i = i + 1
Loop Until i = 4
' Turn on screen updating:
Application.DisplayAlerts = True
End Sub
Public Function FileFolderExists(strFullPath As String) As Boolean
'Author : Ken Puls (www.excelguru.ca)
'Macro Purpose: Check if a file or folder exists
On Error GoTo EarlyExit
If Not Dir(strFullPath, vbDirectory) = vbNullString Then FileFolderExists = True
EarlyExit:
On Error GoTo 0
End Function