Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default move and then unprotect

I have this code to move files from one folder to another. After they are
moved (or before or during - does not matter) , I'd like to unprotect all the
worksheets/workbooks that were moved.
I've seen samples of unprotecting, but they all seem to refer to the current
worksheet (where the macros are being run) as opposed to the destination
worksheets/workbooks. AND I can't figure out where to place them in the code
below.

Can anyone help (the code below is Ron de Bruin's) with code that unprotects
both the workbook and the worksheets that are moved?
Thanks
T


Sub Move_New_WR()
'This example move the folder from FromPath to ToPath.
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String

FromPath = "H:\WR Intake\Test Move" '<< Change
ToPath = "H:\WR Intake New\" '<< Change
'Note: It is not possible to use a folder that exist in ToPath

If Right(FromPath, 1) = "\" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If

If Right(ToPath, 1) = "\" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
End If

Set FSO = CreateObject("scripting.filesystemobject")

If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If

If FSO.FolderExists(ToPath) = True Then
MsgBox ToPath & " exist, not possible to move to a existing folder"
Exit Sub
End If

FSO.MoveFolder Source:=FromPath, Destination:=ToPath
MsgBox "The folder is moved from " & FromPath & " to " & ToPath

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 66
Default move and then unprotect

ALSO:
can I save the moved files a cell (C108 for example) in worksheet 2 as the
name of the file?
Thank you.
T
"Theo" wrote:

I have this code to move files from one folder to another. After they are
moved (or before or during - does not matter) , I'd like to unprotect all the
worksheets/workbooks that were moved.
I've seen samples of unprotecting, but they all seem to refer to the current
worksheet (where the macros are being run) as opposed to the destination
worksheets/workbooks. AND I can't figure out where to place them in the code
below.

Can anyone help (the code below is Ron de Bruin's) with code that unprotects
both the workbook and the worksheets that are moved?
Thanks
T


Sub Move_New_WR()
'This example move the folder from FromPath to ToPath.
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String

FromPath = "H:\WR Intake\Test Move" '<< Change
ToPath = "H:\WR Intake New\" '<< Change
'Note: It is not possible to use a folder that exist in ToPath

If Right(FromPath, 1) = "\" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If

If Right(ToPath, 1) = "\" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
End If

Set FSO = CreateObject("scripting.filesystemobject")

If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If

If FSO.FolderExists(ToPath) = True Then
MsgBox ToPath & " exist, not possible to move to a existing folder"
Exit Sub
End If

FSO.MoveFolder Source:=FromPath, Destination:=ToPath
MsgBox "The folder is moved from " & FromPath & " to " & ToPath

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel arrows don't move black box but move the window Thebit Excel Discussion (Misc queries) 1 April 13th 09 02:06 AM
Can I Move replace instead of Move copy [email protected] Excel Discussion (Misc queries) 2 January 9th 08 10:25 PM
excel-how to get the spreadsheet to move as I move the scroll tab excel toiler Excel Discussion (Misc queries) 6 November 7th 07 06:07 PM
How do I stop making the spreadsht move when I move up/dwn/lt/rt? Manny Excel Worksheet Functions 4 April 7th 06 10:30 PM
When I move scroll bar in excell the contents do not move with it ramneek Excel Discussion (Misc queries) 2 June 29th 05 07:35 PM


All times are GMT +1. The time now is 02:06 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"