ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Move Folders on the Server vs. Local Machine (https://www.excelbanter.com/excel-programming/330192-move-folders-server-vs-local-machine.html)

Myrna Rodriguez[_2_]

Move Folders on the Server vs. Local Machine
 
Hi VB debuggers,

Is there a difference when moving folders on the server and local
machine (server = S:/ local = C:/)??

PROGRAM MISSION:
I have programmed code in Excel VBA to move folders when the user
selects an item in a combo box. Once the user saves the change, the
folder should move to it corresponding path.

PROBLEM:
The code fails when running the program on the server S:/
I get an error message box "Specified path not found"

Where did I go wrong? Thanks in advance for you help and continue to
enjoy life... Myrna Rodriguez


THIS IS THE CODE:
Private Sub cmdots_Click()
'Show OTS Form
UserForm1.Show
End Sub

Private Sub CommandButton1_Click()

Call RegenerateLinks

End Sub


Sub RegenerateLinks()
'Declarations
Dim Nextrow As Long
Dim myRange As Range
Dim x As String
Dim cell As Range
Dim fastNumValue As String
Dim fileLocation As String
Dim link As String
Dim rowCount As Integer
Dim h As Hyperlink
Dim newAddress As String
Dim debugThis As Boolean
Dim newfolder As String

debugThis = False

rowCount = 0

Set myRange = Range("A3").CurrentRegion

For Each rw In Worksheets(1).Cells(1, 1).CurrentRegion.Rows

rowCount = rowCount + 1

fastNumValue = rw.Cells(1, 1).Value
If debugThis Then MsgBox "fastNumValue : " & fastNumValue

fileLocation = rw.Cells(1, 16).Value
If debugThis Then MsgBox "fileLocation : " & fileLocation


For Each h In rw.Hyperlinks

'MsgBox ActiveWorkbook.FullName

link = h.Name
If debugThis Then MsgBox "link h.name : " & link

If InStr(fileLocation, "Open") < 0 Then

If InStr(h.Name, "Open") < 0 Then

If debugThis Then MsgBox "is ok"

ElseIf InStr(h.Name, "Post-Close") < 0 Then

If debugThis Then MsgBox "not ok"

newAddress = Replace(h.Address, "Post-Close", "Open")

If debugThis Then MsgBox "newAddress : " & newAddress

'moving the files now
oldFullAddress = HyperLinkTextH(h)
If debugThis Then MsgBox "oldFullAddress : " &
oldFullAddress

newFullAddress = Replace(oldFullAddress, "Post-Close",
"Open")
If debugThis Then MsgBox "newFullAddress : " &
newFullAddress

Set fso = CreateObject("Scripting.FileSystemObject")
'check if file exists first
If fso.folderexists(oldFullAddress) Then

Set mainfolder = fso.GetFolder(oldFullAddress)
mainfolder.Move newFullAddress

End If

h.Address = newAddress

If debugThis Then MsgBox "newAddress added : " &
h.Address

ElseIf InStr(h.Name, "Archived") < 0 Then

If debugThis Then MsgBox "not ok"
newAddress = Replace(h.Address, "Archived", "Open")

If debugThis Then MsgBox "newAddress : " & newAddress

'moving the files now
oldFullAddress = HyperLinkTextH(h)
If debugThis Then MsgBox "oldFullAddress : " &
oldFullAddress

newFullAddress = Replace(oldFullAddress, "Archived",
"Open")
If debugThis Then MsgBox "newFullAddress : " &
newFullAddress

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.folderexists(oldFullAddress) Then

Set mainfolder = fso.GetFolder(oldFullAddress)
mainfolder.Move newFullAddress

End If

h.Address = newAddress

If debugThis Then MsgBox "newAddress added : " &
h.Address

End If

End If

If InStr(fileLocation, "Post-Close") < 0 Then

If InStr(h.Name, "Open") < 0 Then

If debugThis Then MsgBox "not ok"
newAddress = Replace(h.Address, "Open", "Post-Close")

If debugThis Then MsgBox "newAddress : " & newAddress

'moving the files now
oldFullAddress = HyperLinkTextH(h)
If debugThis Then MsgBox "oldFullAddress : " &
oldFullAddress

newFullAddress = Replace(oldFullAddress, "Open",
"Post-Close")
If debugThis Then MsgBox "newFullAddress : " &
newFullAddress

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.folderexists(oldFullAddress) Then

Set mainfolder = fso.GetFolder(oldFullAddress)
mainfolder.Move newFullAddress

End If

h.Address = newAddress

If debugThis Then MsgBox "newAddress added : " &
h.Address

ElseIf InStr(h.Name, "Post-Close") < 0 Then

If debugThis Then MsgBox "is ok"

ElseIf InStr(h.Name, "Archived") < 0 Then

If debugThis Then MsgBox "not ok"

newAddress = Replace(h.Address, "Archived",
"Post-Close")

If debugThis Then MsgBox "newAddress : " & newAddress

'moving the files now
oldFullAddress = HyperLinkTextH(h)
If debugThis Then MsgBox "oldFullAddress : " &
oldFullAddress

newFullAddress = Replace(oldFullAddress, "Archived",
"Post-Close")
If debugThis Then MsgBox "newFullAddress : " &
newFullAddress

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.folderexists(oldFullAddress) Then

Set mainfolder = fso.GetFolder(oldFullAddress)
mainfolder.Move newFullAddress

End If
h.Address = newAddress

If debugThis Then MsgBox "newAddress added : " &
h.Address

End If

End If

If InStr(fileLocation, "Archived") < 0 Then

If InStr(h.Name, "Open") < 0 Then

If debugThis Then MsgBox "not ok"

newAddress = Replace(h.Address, "Open", "Archived")

If debugThis Then MsgBox "newAddress : " & newAddress

h.Address = newAddress

'moving the files now
oldFullAddress = HyperLinkTextH(h)
If debugThis Then MsgBox "oldFullAddress : " &
oldFullAddress

newFullAddress = Replace(oldFullAddress, "Open",
"Archived")
If debugThis Then MsgBox "newFullAddress : " &
newFullAddress

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.folderexists(oldFullAddress) Then

Set mainfolder = fso.GetFolder(oldFullAddress)
mainfolder.Move newFullAddress

End If

If debugThis Then MsgBox "newAddress added : " &
h.Address

ElseIf InStr(h.Name, "Post-Close") < 0 Then

If debugThis Then MsgBox "not ok"
newAddress = Replace(h.Address, "Post-Close",
"Archived")

If debugThis Then MsgBox "newAddress : " & newAddress

'moving the
files now
oldFullAddress = HyperLinkTextH(h)
If debugThis Then MsgBox "oldFullAddress : " & oldFullAddress

newFullAddress = Replace(oldFullAddress, "Post-Close", "Archived")
If debugThis Then MsgBox "newFullAddress : " &
newFullAddress

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.folderexists(oldFullAddress) Then

Set mainfolder = fso.GetFolder(oldFullAddress)
mainfolder.Move newFullAddress

End If

h.Address = newAddress

If debugThis Then MsgBox "newAddress added : " &
h.Address

ElseIf InStr(h.Name, "Archived") < 0 Then

If debugThis Then MsgBox "is ok"

End If

End If

Next

Next

If debugThis Then MsgBox rowCount

End Sub

*** Sent via Developersdex http://www.developersdex.com ***

K Dales[_2_]

Move Folders on the Server vs. Local Machine
 
I don't see where you declare your mainfolder variable. It is being used to
move the folder so its role is important, and perhaps declaring it explicitly
as an object variable would help.

Other than that it is hard to tell what the problem is without knowing which
line of code is throwing the error. I would guess it is in here somewhe
Set mainfolder = fso.GetFolder(oldFullAddress)
mainfolder.Move newFullAddress
but without knowing which line, or being able to test the values and
properties of your variables at that point it is hard to say why it fails.

"Myrna Rodriguez" wrote:

Hi VB debuggers,

Is there a difference when moving folders on the server and local
machine (server = S:/ local = C:/)??

PROGRAM MISSION:
I have programmed code in Excel VBA to move folders when the user
selects an item in a combo box. Once the user saves the change, the
folder should move to it corresponding path.

PROBLEM:
The code fails when running the program on the server S:/
I get an error message box "Specified path not found"

Where did I go wrong? Thanks in advance for you help and continue to
enjoy life... Myrna Rodriguez


THIS IS THE CODE:
Private Sub cmdots_Click()
'Show OTS Form
UserForm1.Show
End Sub

Private Sub CommandButton1_Click()

Call RegenerateLinks

End Sub


Sub RegenerateLinks()
'Declarations
Dim Nextrow As Long
Dim myRange As Range
Dim x As String
Dim cell As Range
Dim fastNumValue As String
Dim fileLocation As String
Dim link As String
Dim rowCount As Integer
Dim h As Hyperlink
Dim newAddress As String
Dim debugThis As Boolean
Dim newfolder As String

debugThis = False

rowCount = 0

Set myRange = Range("A3").CurrentRegion

For Each rw In Worksheets(1).Cells(1, 1).CurrentRegion.Rows

rowCount = rowCount + 1

fastNumValue = rw.Cells(1, 1).Value
If debugThis Then MsgBox "fastNumValue : " & fastNumValue

fileLocation = rw.Cells(1, 16).Value
If debugThis Then MsgBox "fileLocation : " & fileLocation


For Each h In rw.Hyperlinks

'MsgBox ActiveWorkbook.FullName

link = h.Name
If debugThis Then MsgBox "link h.name : " & link

If InStr(fileLocation, "Open") < 0 Then

If InStr(h.Name, "Open") < 0 Then

If debugThis Then MsgBox "is ok"

ElseIf InStr(h.Name, "Post-Close") < 0 Then

If debugThis Then MsgBox "not ok"

newAddress = Replace(h.Address, "Post-Close", "Open")

If debugThis Then MsgBox "newAddress : " & newAddress

'moving the files now
oldFullAddress = HyperLinkTextH(h)
If debugThis Then MsgBox "oldFullAddress : " &
oldFullAddress

newFullAddress = Replace(oldFullAddress, "Post-Close",
"Open")
If debugThis Then MsgBox "newFullAddress : " &
newFullAddress

Set fso = CreateObject("Scripting.FileSystemObject")
'check if file exists first
If fso.folderexists(oldFullAddress) Then

Set mainfolder = fso.GetFolder(oldFullAddress)
mainfolder.Move newFullAddress

End If

h.Address = newAddress

If debugThis Then MsgBox "newAddress added : " &
h.Address

ElseIf InStr(h.Name, "Archived") < 0 Then

If debugThis Then MsgBox "not ok"
newAddress = Replace(h.Address, "Archived", "Open")

If debugThis Then MsgBox "newAddress : " & newAddress

'moving the files now
oldFullAddress = HyperLinkTextH(h)
If debugThis Then MsgBox "oldFullAddress : " &
oldFullAddress

newFullAddress = Replace(oldFullAddress, "Archived",
"Open")
If debugThis Then MsgBox "newFullAddress : " &
newFullAddress

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.folderexists(oldFullAddress) Then

Set mainfolder = fso.GetFolder(oldFullAddress)
mainfolder.Move newFullAddress

End If

h.Address = newAddress

If debugThis Then MsgBox "newAddress added : " &
h.Address

End If

End If

If InStr(fileLocation, "Post-Close") < 0 Then

If InStr(h.Name, "Open") < 0 Then

If debugThis Then MsgBox "not ok"
newAddress = Replace(h.Address, "Open", "Post-Close")

If debugThis Then MsgBox "newAddress : " & newAddress

'moving the files now
oldFullAddress = HyperLinkTextH(h)
If debugThis Then MsgBox "oldFullAddress : " &
oldFullAddress

newFullAddress = Replace(oldFullAddress, "Open",
"Post-Close")
If debugThis Then MsgBox "newFullAddress : " &
newFullAddress

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.folderexists(oldFullAddress) Then

Set mainfolder = fso.GetFolder(oldFullAddress)
mainfolder.Move newFullAddress

End If

h.Address = newAddress

If debugThis Then MsgBox "newAddress added : " &
h.Address

ElseIf InStr(h.Name, "Post-Close") < 0 Then

If debugThis Then MsgBox "is ok"

ElseIf InStr(h.Name, "Archived") < 0 Then

If debugThis Then MsgBox "not ok"

newAddress = Replace(h.Address, "Archived",
"Post-Close")

If debugThis Then MsgBox "newAddress : " & newAddress

'moving the files now
oldFullAddress = HyperLinkTextH(h)
If debugThis Then MsgBox "oldFullAddress : " &
oldFullAddress

newFullAddress = Replace(oldFullAddress, "Archived",
"Post-Close")
If debugThis Then MsgBox "newFullAddress : " &
newFullAddress

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.folderexists(oldFullAddress) Then

Set mainfolder = fso.GetFolder(oldFullAddress)
mainfolder.Move newFullAddress

End If
h.Address = newAddress

If debugThis Then MsgBox "newAddress added : " &
h.Address

End If

End If

If InStr(fileLocation, "Archived") < 0 Then

If InStr(h.Name, "Open") < 0 Then

If debugThis Then MsgBox "not ok"

newAddress = Replace(h.Address, "Open", "Archived")

If debugThis Then MsgBox "newAddress : " & newAddress

h.Address = newAddress

'moving the files now
oldFullAddress = HyperLinkTextH(h)
If debugThis Then MsgBox "oldFullAddress : " &
oldFullAddress

newFullAddress = Replace(oldFullAddress, "Open",
"Archived")
If debugThis Then MsgBox "newFullAddress : " &
newFullAddress

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.folderexists(oldFullAddress) Then

Set mainfolder = fso.GetFolder(oldFullAddress)
mainfolder.Move newFullAddress

End If

If debugThis Then MsgBox "newAddress added : " &
h.Address

ElseIf InStr(h.Name, "Post-Close") < 0 Then

If debugThis Then MsgBox "not ok"
newAddress = Replace(h.Address, "Post-Close",
"Archived")

If debugThis Then MsgBox "newAddress : " & newAddress

'moving the
files now
oldFullAddress = HyperLinkTextH(h)
If debugThis Then MsgBox "oldFullAddress : " & oldFullAddress

newFullAddress = Replace(oldFullAddress, "Post-Close", "Archived")
If debugThis Then MsgBox "newFullAddress : " &
newFullAddress

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.folderexists(oldFullAddress) Then

Set mainfolder = fso.GetFolder(oldFullAddress)
mainfolder.Move newFullAddress

End If

h.Address = newAddress

If debugThis Then MsgBox "newAddress added : " &
h.Address

ElseIf InStr(h.Name, "Archived") < 0 Then

If debugThis Then MsgBox "is ok"

End If

End If

Next

Next

If debugThis Then MsgBox rowCount

End Sub

*** Sent via Developersdex http://www.developersdex.com ***



All times are GMT +1. The time now is 11:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com