Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Save and print if change made

Sub ReplaceAndPrint()

' strFolder = "path to main folder"
strFolder = "C:\Documents and Settings\dwilson\Desktop\Correction"
Set fso = CreateObject _
("Scripting.FileSystemObject")
Set Folder = _
fso.GetFolder(strFolder)

Call ReplaceAndPrintSubFolder(strFolder + "\")
End Sub

Sub ReplaceAndPrintSubFolder(strFolder)
Set fso = CreateObject _
("Scripting.FileSystemObject")

Set Folder = _
fso.GetFolder(strFolder)

If Folder.subfolders.Count 0 Then
For Each sf In Folder.subfolders
On Error GoTo 100
Call ReplaceAndPrintSubFolder(strFolder + sf.Name + "\")
100 Next sf
End If
'folder size in bytes
On Error GoTo 200
For Each fl In Folder.Files
Ext = fso.GetExtensionName(fl)
If UCase(Left(Ext, 2)) = "XL" Then

Set mybook = Nothing
On Error Resume Next
Set mybook = Workbooks.Open(fl)
On Error GoTo 0

If Not mybook Is Nothing Then

'Change cell value(s)
On Error Resume Next

'Experimental Coding

Application.DisplayAlerts = False
Application.ScreenUpdating = False

With mybook.Worksheets("Report")

Cells.Replace What:= _
"Place 2 labels per carton, 1 on front, and 1 on end.",
Replacement:= _
"Place a label on the end of each carton.", LookAt:=xlPart,
SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:= _
"Place 2 labels per carton, 1 on front, and one on end.",
Replacement:= _
"Place a label on the end of each carton.", LookAt:=xlPart,
SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:= _
"Place 2 labels per carton, one on front, and one on end.",
Replacement:= _
"Place a label on the end of each carton.", LookAt:=xlPart,
SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Worksheets("Report").Select
Range("I2").Select

ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True
End With

If Err.Number 0 Then
ErrYes = True
Err.Clear
'close without saving
mybook.Close savechanges:=False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Else
mybook.Close savechanges:=True
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End If
Else
ErrorYes = True
End If
End If
Next fl
200 On Error GoTo 0

End Sub





  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Save and print if change made

Check your other post.

Kiba wrote:

Sub ReplaceAndPrint()

' strFolder = "path to main folder"
strFolder = "C:\Documents and Settings\dwilson\Desktop\Correction"
Set fso = CreateObject _
("Scripting.FileSystemObject")
Set Folder = _
fso.GetFolder(strFolder)

Call ReplaceAndPrintSubFolder(strFolder + "\")
End Sub

Sub ReplaceAndPrintSubFolder(strFolder)
Set fso = CreateObject _
("Scripting.FileSystemObject")

Set Folder = _
fso.GetFolder(strFolder)

If Folder.subfolders.Count 0 Then
For Each sf In Folder.subfolders
On Error GoTo 100
Call ReplaceAndPrintSubFolder(strFolder + sf.Name + "\")
100 Next sf
End If
'folder size in bytes
On Error GoTo 200
For Each fl In Folder.Files
Ext = fso.GetExtensionName(fl)
If UCase(Left(Ext, 2)) = "XL" Then

Set mybook = Nothing
On Error Resume Next
Set mybook = Workbooks.Open(fl)
On Error GoTo 0

If Not mybook Is Nothing Then

'Change cell value(s)
On Error Resume Next

'Experimental Coding

Application.DisplayAlerts = False
Application.ScreenUpdating = False

With mybook.Worksheets("Report")

Cells.Replace What:= _
"Place 2 labels per carton, 1 on front, and 1 on end.",
Replacement:= _
"Place a label on the end of each carton.", LookAt:=xlPart,
SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:= _
"Place 2 labels per carton, 1 on front, and one on end.",
Replacement:= _
"Place a label on the end of each carton.", LookAt:=xlPart,
SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Cells.Replace What:= _
"Place 2 labels per carton, one on front, and one on end.",
Replacement:= _
"Place a label on the end of each carton.", LookAt:=xlPart,
SearchOrder:= _
xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False

Worksheets("Report").Select
Range("I2").Select

ActiveWindow.SelectedSheets.PrintOut Copies:=2, Collate:=True
End With

If Err.Number 0 Then
ErrYes = True
Err.Clear
'close without saving
mybook.Close savechanges:=False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Else
mybook.Close savechanges:=True
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End If
Else
ErrorYes = True
End If
End If
Next fl
200 On Error GoTo 0

End Sub


--

Dave Peterson
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
Only save and print if change made Kiba Excel Discussion (Misc queries) 3 January 7th 09 06:35 PM
Save changes? even when you've made none Donna Excel Discussion (Misc queries) 3 November 20th 08 10:17 PM
save changes when no changes made Elaine Excel Discussion (Misc queries) 2 January 19th 06 12:55 AM
i made one spreadsheet but when i try to print two sheets print, yokhan Excel Discussion (Misc queries) 1 August 14th 05 09:24 AM
i made change in a current workbook and accidentally save it, can. angel Excel Discussion (Misc queries) 1 January 4th 05 01:11 AM


All times are GMT +1. The time now is 09:49 PM.

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"