Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Problème lenteur macro

1 réponse
Avatar
Christophe
Bonjour:

Le code vba (ci-dessous) est pour l'essentiel le resultat de
l'enregistreur de macro auxquel j'ai rajout=E9 des lignes de code
regulierement et est par consequent devenu tres tres tres lent. Pouvez-
vous m'indiquer les lignes qui de votre point de vue pose le plus de
probleme de rapidite et comment les modifier. Merci d'avance pour
votre aide.

Sinc=E8res salutations.

Christophe

Sub ShowtimeCompanyScheduler()
If MsgBox(Prompt:=3D"Are you really sure to want to GENERATE the
COMPANY SCHEDULES of Appointments? If yes, it can take up to a few
minutes depending on the number of companies/countries.",
Buttons:=3DvbYesNo + vbQuestion, _
Title:=3D"Generate Company Schedules") =3D vbNo Then
Exit Sub
End If
' Showtime Scheduler Macro
' Macro enregistr=E9e le 29/04/2003 par Christophe
Application.ScreenUpdating =3D False
' Unprotect Worksheet
ActiveWorkbook.Unprotect Password:=3D"*****"
Worksheets("Company Data").Select

' save last changes made at Worksheet "Country Appointments"
Worksheets("Country Appointments").Select
'ActiveSheet.Unprotect Password:=3D"*****"
Cells.Select
Cells.EntireColumn.AutoFit
ActiveWorkbook.Save
'TEST CreateBackup =3D True
'ActiveSheet.Protect Password:=3D"*****", DrawingObjects:=3DTrue,
Contents:=3DTrue, Scenarios:=3DTrue

'Delete all Worksheets except 9 of them
ActiveWorkbook.Unprotect Password:=3D"*****"
Application.DisplayAlerts =3D False
For Each S In ActiveWorkbook.Worksheets
If S.Name <> "What is the Scheduler" And S.Name <>
"Instructions" And S.Name <> "Country Data" And S.Name <> _
"Company Data" And S.Name <> "Country Appointments" And
S.Name <> "Fax Template" And S.Name <> "Statistics" And S.Name <>
"EmailAllCountrySchedules" And S.Name <> "EmailAllCompanySchedules"
And S.Name <> "Transitory4" And S.Name <> "Transitory6" Then S.Delete
Next S
Application.DisplayAlerts =3D False

'Create Copy content-value of "Country Appointments" moins colonne
A into "Transitory1" (no formulas).
Cells.Select
Selection.Copy
Sheets.Add.Name =3D "Transitory1"
Range("A1").Select
Selection.PasteSpecial Paste:=3DxlAll, Operation:=3DxlNone,
SkipBlanks:=3DFalse _
, Transpose:=3DFalse
Selection.Columns.AutoFit


'Run macro "SwapTableShowtime" Range is automaticaly selected
'Then result is saved into "Company Appointments" worksheet and
cell A1 is filled with Date / Time label
ActiveSheet.Name =3D "Transitory1"
Columns("A:A").Select
Application.CutCopyMode =3D False
Selection.Delete Shift:=3DxlToLeft

Application.Run "ShowtimeSwapTable"
ActiveSheet.Name =3D "Company Appointments"
Range("A1").Select
Application.CutCopyMode =3D False
Selection.Font.Bold =3D True
ActiveCell.FormulaR1C1 =3D "DATE & TIME"

' Replace "H#" by empty cell otherwise program stop as it cannot
find empty cells in some columns.
'It might be possible and better instead to use something like
"Application.DisplayAlerts =3D False"
Cells.Select
Selection.Replace What:=3D"H#", Replacement:=3D"", LookAt:=3DxlPart, _
SearchOrder:=3DxlByRows, MatchCase:=3DFalse

'Copy and paste result into "Transitory2" worksheet
Cells.Select
Application.CutCopyMode =3D False
Selection.Copy
Range("A1").Select
Sheets.Add.Name =3D "Transitory2"
ActiveSheet.Paste
Columns("A:A").Select
Selection.NumberFormat =3D "m/d/yy h:mm AM/PM"

'Loop 120 times (if number of companies participating in Showtime
exceed 120 please increase number in macro)
'to copy the first two columns of "Transitory2" worksheet and
paste it each time in a new sheet
'named by the company name in cell "B1" (note that a variable
Onglet was created)
'Remove the date and time for which the company does not have
meeting scheduled by deleting rows with empty cell (F5 Special Blank)
' Each loop Deletes in "Transitory2" the column of the company
processed


For I =3D 1 To 120
If Application.WorksheetFunction.CountA(Range("B2:B115")) =3D 0
Then
GoTo Suite1
End If


Dim Onglet As String


Columns("A:B").Select
Selection.Copy
Sheets.Add
Range("A1").Select
ActiveSheet.Paste
Onglet =3D ActiveSheet.Range("B1").Value

'si la cha=EEne "Onglet" est vide
If Onglet =3D "" Then
Onglet =3D "ZZZZZ"
GoTo Suite
End If
'si le nom comprend des caract=E8res interdits -> tiret bas
For j =3D 1 To Len(Onglet)
Select Case Mid(Onglet, j, 1)
Case "&", ":", "/", "\", "?", "*", "[", "]": Mid(Onglet,
j, 1) =3D "_"
End Select
Next
'si le nom est trop long -> tronqu=E9 =E0 31 caract=E8res
If Len(Onglet) > 31 Then
Onglet =3D Left(Onglet, 31)
End If

ActiveSheet.Name =3D Onglet
Range("B2:B" &
Range("B65536").End(xlUp).Row).SpecialCells(xlCellTypeBlanks).EntireRow.Del=
ete


'Add 14 lines to the top of each sheet. Move company name 2
cells above. Rename column to "Country" and add name to column "Trade
Specialist".
'Merge column first and lastname. Copy formulas to look for
corresponding firstname and lastname into sheet "CountryData".
Columns("A").Select
With Selection
.HorizontalAlignment =3D xlLeft
.VerticalAlignment =3D xlBottom
.WrapText =3D False
.Orientation =3D 0
.AddIndent =3D False
.IndentLevel =3D 0
.ShrinkToFit =3D False
.MergeCells =3D False
End With
Range("A1").Select
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert
Selection.EntireRow.Insert

'ChDir "C:\Program Files\Showtime Scheduler\"
Range("A1").Select
Rows("1:1").RowHeight =3D 110
ActiveSheet.Pictures.Insert("C:\Program Files\Showtime
Scheduler\uscslogo2.jpg").Select
With Selection
.Top =3D Range("A1").Top
.Left =3D Range("A1").Left
.Width =3D Range("A1").Width
.Height =3D Range("A1").Height
End With


Range("B15").Select
Selection.Cut
Range("B13").Select
ActiveSheet.Paste
Range("B13").Select
Selection.Font.Bold =3D True
Range("B15").Select
Selection.Font.Bold =3D True
ActiveCell.FormulaR1C1 =3D "COMPANY"
Range("C15").Select
ActiveCell.FormulaR1C1 =3D "CONTACT NAME"
Range("A13").Select
Selection.Font.Bold =3D True
ActiveCell.FormulaR1C1 =3D "Schedule for: "

'TEST Range("C13").Select
'TEST ActiveCell.Formula =3D "=3DA13&"" ""&B13"
' TEST Range("C13").Select
' TEST Selection.Copy
' TEST Range("D13").Select
' TEST Selection.PasteSpecial Paste:=3DxlValues,
Operation:=3DxlNone, SkipBlanks:=3D _
False, Transpose:=3DFalse
' TEST Range("A13:C13").Select
' TEST Selection.Delete Shift:=3DxlToLeft
' TEST Selection.Font.Bold =3D True
' TEST Range("A13").Select

'underline (border) titles
Range("A15:C15").Select
Selection.Borders(xlDiagonalDown).LineStyle =3D xlNone
Selection.Borders(xlDiagonalUp).LineStyle =3D xlNone
Selection.Borders(xlEdgeLeft).LineStyle =3D xlNone
Selection.Borders(xlEdgeTop).LineStyle =3D xlNone
With Selection.Borders(xlEdgeBottom)
.LineStyle =3D xlContinuous
.Weight =3D xlThick
.ColorIndex =3D xlAutomatic
End With
Selection.Borders(xlEdgeRight).LineStyle =3D xlNone
Selection.Borders(xlInsideVertical).LineStyle =3D xlNone


Range("C16").Select
ActiveCell.FormulaR1C1 =3D _
"=3DIF(ISERROR(VLOOKUP(RC[-1],CountryData,2,FALSE)),"""",
(VLOOKUP(RC[-1],CountryData,2,FALSE)))"
Range("C16").Select
Selection.Copy
Range("C17:D47").Select
Selection.PasteSpecial Paste:=3DxlPasteFormulas,
Operation:=3DxlNone, _
SkipBlanks:=3DFalse, Transpose:=3DFalse
Application.CutCopyMode =3D False

Range("D16").Select
ActiveCell.FormulaR1C1 =3D _
"=3DIF(ISERROR(VLOOKUP(RC[-2],CountryData,3,FALSE)),"""",
(VLOOKUP(RC[-2],CountryData,3,FALSE)))"
Range("D16").Select
Selection.Copy
Range("D17:D47").Select
Selection.PasteSpecial Paste:=3DxlPasteFormulas,
Operation:=3DxlNone, _
SkipBlanks:=3DFalse, Transpose:=3DFalse
Application.CutCopyMode =3D False

Range("E15").Select
ActiveCell.Formula =3D "=3DC15&"" ""&D15"
Range("E15").Select
Selection.Copy
Range("E16:E48").Select
Selection.PasteSpecial Paste:=3DxlPasteFormulas,
Operation:=3DxlNone, _
SkipBlanks:=3DFalse, Transpose:=3DFalse
Application.CutCopyMode =3D False

Columns("E:E").Select
Selection.Copy
Columns("F:F").Select
Selection.PasteSpecial Paste:=3DxlValues, Operation:=3DxlNone,
SkipBlanks:=3D _
False, Transpose:=3DFalse
Columns("C:F").Select
Range("F13").Activate
Application.CutCopyMode =3D False
Columns("C:E").Select
Range("E13").Activate
Selection.Delete Shift:=3DxlToLeft
Range("C15").Select
Selection.Font.Bold =3D True
Range("A15:C15").Select
Selection.Borders(xlDiagonalDown).LineStyle =3D xlNone
Selection.Borders(xlDiagonalUp).LineStyle =3D xlNone
Selection.Borders(xlEdgeLeft).LineStyle =3D xlNone
Selection.Borders(xlEdgeTop).LineStyle =3D xlNone
With Selection.Borders(xlEdgeBottom)
.LineStyle =3D xlContinuous
.Weight =3D xlThick
.ColorIndex =3D xlAutomatic
End With
Selection.Borders(xlEdgeRight).LineStyle =3D xlNone
Selection.Borders(xlInsideVertical).LineStyle =3D xlNone

Range("A3").Select
ActiveCell.Formula =3D
"=3DIF(ISERROR(VLOOKUP(B13,COMPANY2,14,FALSE)),"""",
(VLOOKUP(B13,COMPANY2,14,FALSE)))&""
""&IF(ISERROR(VLOOKUP(B13,COMPANY2,15,FALSE)),"""",
(VLOOKUP(B13,COMPANY2,15,FALSE)))&""
""&IF(ISERROR(VLOOKUP(B13,COMPANY2,16,FALSE)),"""",
(VLOOKUP(B13,COMPANY2,16,FALSE)))"

Selection.Copy
Selection.PasteSpecial Paste:=3DxlPasteValues,
Operation:=3DxlNone, SkipBlanks _
:=3DF=
alse,
Transpose:=3DFalse
With Selection.Font
.Name =3D "Arial"
.FontStyle =3D "Gras"
.Size =3D 10
.Strikethrough =3D False
.Superscript =3D False
.Subscript =3D False
.OutlineFont =3D False
.Shadow =3D False
.Underline =3D xlUnderlineStyleNone
.ColorIndex =3D xlAutomatic
.TintAndShade =3D 0
.ThemeFont =3D xlThemeFontNone
End With
Range("A3").Select
Selection.Font.Bold =3D True

Range("A4:B4").Select
With Selection
.HorizontalAlignment =3D xlLeft
.VerticalAlignment =3D xlBottom
.WrapText =3D False
.Orientation =3D 0
.AddIndent =3D False
.IndentLevel =3D 0
.ShrinkToFit =3D False
.ReadingOrder =3D xlContext
.MergeCells =3D True
End With
Range("A5:B5").Select
With Selection
.HorizontalAlignment =3D xlLeft
.VerticalAlignment =3D xlBottom
.WrapText =3D False
.Orientation =3D 0
.AddIndent =3D False
.IndentLevel =3D 0
.ShrinkToFit =3D False
.ReadingOrder =3D xlContext
.MergeCells =3D True
End With
Range("A6:B6").Select
With Selection
.HorizontalAlignment =3D xlLeft
.VerticalAlignment =3D xlBottom
.WrapText =3D False
.Orientation =3D 0
.AddIndent =3D False
.IndentLevel =3D 0
.ShrinkToFit =3D False
.ReadingOrder =3D xlContext
.MergeCells =3D True
End With
Range("A7:B7").Select
With Selection
.HorizontalAlignment =3D xlLeft
.VerticalAlignment =3D xlBottom
.WrapText =3D False
.Orientation =3D 0
.AddIndent =3D False
.IndentLevel =3D 0
.ShrinkToFit =3D False
.ReadingOrder =3D xlContext
.MergeCells =3D True
End With
Range("A8:B8").Select
With Selection
.HorizontalAlignment =3D xlLeft
.VerticalAlignment =3D xlBottom
.WrapText =3D False
.Orientation =3D 0
.AddIndent =3D False
.IndentLevel =3D 0
.ShrinkToFit =3D False
.ReadingOrder =3D xlContext
.MergeCells =3D True
End With

Range("A4").Select
Selection.Formula =3D
"=3DIF(or(ISERROR(VLOOKUP(B13,COMPANY2,17,False)),VLOOKUP(B13,COMPANY2,17,F=
alse)=3D0),"""",
(VLOOKUP(B13,COMPANY2,17,False)))"
Selection.Copy
Selection.PasteSpecial Paste:=3DxlPasteValues,
Operation:=3DxlNone, SkipBlanks _
:=3DF=
alse,
Transpose:=3DFalse

Range("A5").Select
Selection.Formula =3D
"=3DIF(ISERROR(VLOOKUP(B13,COMPANY2,1,False)),"""",
(VLOOKUP(B13,COMPANY2,1,False)))"
Selection.Copy
Selection.PasteSpecial Paste:=3DxlPasteValues,
Operation:=3DxlNone, SkipBlanks _
:=3DF=
alse,
Transpose:=3DFalse

Range("A6").Select
Selection.Formula =3D
"=3DIF(or(ISERROR(VLOOKUP(B13,COMPANY2,4,False)),VLOOKUP(B13,COMPANY2,4,Fal=
se)=3D0),"""",
(VLOOKUP(B13,COMPANY2,4,False)))"
Selection.Copy
Selection.PasteSpecial Paste:=3DxlPasteValues,
Operation:=3DxlNone, SkipBlanks _
:=3DF=
alse,
Transpose:=3DFalse

Range("A7").Select
ActiveCell.Formula =3D
"=3DIF(ISERROR(VLOOKUP(B13,COMPANY2,5,False)),"""",
(VLOOKUP(B13,COMPANY2,5,False)))&""
""&IF(ISERROR(VLOOKUP(B13,COMPANY2,6,False)),"""",
(VLOOKUP(B13,COMPANY2,6,False)))&""
""&IF(ISERROR(VLOOKUP(B13,COMPANY2,7,False)),"""",
(VLOOKUP(B13,COMPANY2,7,False)))"
Selection.Copy
Selection.PasteSpecial Paste:=3DxlPasteValues,
Operation:=3DxlNone, SkipBlanks _
:=3DF=
alse,
Transpose:=3DFalse

Range("A8").Select
ActiveCell.Formula =3D "=3DCONCATENATE(VLOOKUP(B13,COMPANY2,21),""
or VIA FAX: "",VLOOKUP(B13,COMPANY2,20))"
Selection.Copy
Selection.PasteSpecial Paste:=3DxlPasteValues,
Operation:=3DxlNone, SkipBlanks _
:=3DF=
alse,
Transpose:=3DFalse
With Selection.Font
.Name =3D "Arial"
.FontStyle =3D "Gras"
.Size =3D 10
.Strikethrough =3D False
.Superscript =3D False
.Subscript =3D False
.OutlineFont =3D False
.Shadow =3D False
.Underline =3D xlUnderlineStyleNone
.ColorIndex =3D xlAutomatic
.TintAndShade =3D 0
.ThemeFont =3D xlThemeFontNone
End With
Range("A8").Select
Selection.Copy
Selection.PasteSpecial Paste:=3DxlPasteValues,
Operation:=3DxlNone, SkipBlanks _
:=3DF=
alse,
Transpose:=3DFalse

Range("A10").Select
ActiveCell.Formula =3D "=3DCONCATENATE(""Dear
"",VLOOKUP(B13,COMPANY2,14),"" "",VLOOKUP(B13,COMPANY2,16),"":"")"
Selection.Copy
Selection.PasteSpecial Paste:=3DxlPasteValues,
Operation:=3DxlNone, SkipBlanks _
:=3DF=
alse,
Transpose:=3DFalse


Range("A12:D12").Select

'Rows("12:12").RowHeight =3D 150
ActiveCell.Formula =3D "=3DCONCATENATE(Body,""
"",VLOOKUP(B13,COMPANY2,2),"""",VLOOKUP(B13,COMPANY2,3,FALSE))"

Selection.Copy
Selection.PasteSpecial Paste:=3DxlPasteValues,
Operation:=3DxlNone, SkipBlanks _
:=3DF=
alse,
Transpose:=3DFalse
With Selection.Font
.Name =3D "Arial"
.Size =3D 10
.Strikethrough =3D False
.Superscript =3D False
.Subscript =3D False
.OutlineFont =3D False
.Shadow =3D False
.Underline =3D xlUnderlineStyleNone
.ColorIndex =3D xlAutomatic
.TintAndShade =3D 0
.ThemeFont =3D xlThemeFontNone
End With

Range("A12").Select
With Selection
.HorizontalAlignment =3D xlLeft
.VerticalAlignment =3D xlTop
.WrapText =3D True
.Orientation =3D 0
.AddIndent =3D False
.IndentLevel =3D 0
.ShrinkToFit =3D False
.ReadingOrder =3D xlContext
.MergeCells =3D False
End With
Range("A12:C12").Select
With Selection
.Orientation =3D 0
.AddIndent =3D False
.ShrinkToFit =3D False
.ReadingOrder =3D xlContext
.MergeCells =3D True
End With
Rows("12:12").RowHeight =3D 150
Columns("B:C").Select
Columns("B:C").EntireColumn.AutoFit



Range("A8:B8").Select
With Selection
.HorizontalAlignment =3D xlCenter
.VerticalAlignment =3D xlBottom
.WrapText =3D False
.Orientation =3D 0
.AddIndent =3D False
.IndentLevel =3D 0
.ShrinkToFit =3D False
.ReadingOrder =3D xlContext
.MergeCells =3D False
End With
Selection.Merge
With Selection
.HorizontalAlignment =3D xlLeft
.VerticalAlignment =3D xlBottom
.WrapText =3D False
.Orientation =3D 0
.AddIndent =3D False
.IndentLevel =3D 0
.ShrinkToFit =3D False
.ReadingOrder =3D xlContext
.MergeCells =3D True
End With
'Range("A10:E10").Select
'With Selection
' .HorizontalAlignment =3D xlCenter
' .VerticalAlignment =3D xlBottom
' .WrapText =3D False
' .Orientation =3D 0
' .AddIndent =3D False
' .IndentLevel =3D 0
' .ShrinkToFit =3D False
' .ReadingOrder =3D xlContext
' .MergeCells =3D False
' End With
'Selection.Merge
' With Selection
' .HorizontalAlignment =3D xlLeft
' .VerticalAlignment =3D xlBottom
' .WrapText =3D False
' .Orientation =3D 0
' .AddIndent =3D False
' .IndentLevel =3D 0
' .ShrinkToFit =3D False
' .ReadingOrder =3D xlContext
' .MergeCells =3D True
'End With

Range("C13").Select
ActiveCell.Formula =3D "=3DCONCATENATE(""Booth#:
"",VLOOKUP(B13,COMPANY2,22),"" Tel/Cell# at show:
"",VLOOKUP(B13,COMPANY2,19))"
'Range("A8").Select
'ActiveCell.Formula =3D "=3DCONCATENATE(""VIA
FAX:"",VLOOKUP(B13,COMPANY2,20),"" or E-mail:
"",VLOOKUP(B13,COMPANY2,21)"


ActiveSheet.UsedRange
Range("a" & Range("a65536").End(xlUp).Row + 3).Select
Range("A" & ActiveCell.Row & ":C" & ActiveCell.Row).Merge
With Selection
.HorizontalAlignment =3D xlGeneral
.VerticalAlignment =3D xlTop
.WrapText =3D True
.Orientation =3D 0
.AddIndent =3D False
.IndentLevel =3D 0
.ShrinkToFit =3D False
.ReadingOrder =3D xlContext
.MergeCells =3D True
End With


Range("A" & ActiveCell.Row & ":C" &
ActiveCell.Row).FormulaR1C1 =3D "=3DSignature"
ActiveCell.RowHeight =3D 300
Range("C2").Select
ActiveCell.FormulaR1C1 =3D "=3DNOW()"
Selection.NumberFormat =3D "m/d/yy h:mm AM/PM"
Range("C2").Select
Columns("C:C").EntireColumn.AutoFit


Range("A2").Select

Cells.Select
With Selection.Interior
.ColorIndex =3D 2
.Pattern =3D xlSolid
.PatternColorIndex =3D xlAutomatic
End With
Range("B13").Select
'ActiveSheet.Protect password:=3D"*****", DrawingObjects:=3DTrue,
Contents:=3DTrue, Scenarios:=3DTrue

Columns("A:C").Select
Columns("A:C").EntireColumn.AutoFit
'Maximize the size of the schedules columns
Cells.Select
Cells.EntireColumn.AutoFit

'Concatenate cells A13, B13 and C13
Range("C13").Select
Selection.Copy
Selection.PasteSpecial Paste:=3DxlPasteValues,
Operation:=3DxlNone, SkipBlanks _
:=3DF=
alse,
Transpose:=3DFalse

Range("D13").Select
ActiveCell.FormulaR1C1 =3D "=3DCONCATENATE(RC[-3],RC[-2],"" -
"",RC[-1])"
Range("D13").Select
Selection.Copy
Selection.PasteSpecial Paste:=3DxlPasteValues,
Operation:=3DxlNone, SkipBlanks _
:=3DF=
alse,
Transpose:=3DFalse
Range("A13:C13").Select
Application.CutCopyMode =3D False
Selection.Delete Shift:=3DxlToLeft
Range("A13").Select
With Selection.Font
.Name =3D "Arial"
.FontStyle =3D "Bold"
.Size =3D 11
.Strikethrough =3D False
.Superscript =3D False
.Subscript =3D False
.OutlineFont =3D False
.Shadow =3D False
.Underline =3D xlUnderlineStyleNone
.ColorIndex =3D xlAutomatic
.TintAndShade =3D 0
.ThemeFont =3D xlThemeFontNone


End With
Columns("A:A").Select
Selection.ColumnWidth =3D 32

'Range("$A$1:$C$" & Range("A65536").End(xlUp).Row).Select




'Maximize the size of the schedules for column B
Columns("B:C").Select
Columns("B:C").EntireColumn.AutoFit
'Range("$A$1:$C$" & Range("A65536").End(xlUp).Row).Select


Dim ce As Range
derlg =3D Cells(Rows.Count, "A").End(3).Row
Range("a15:ce" & derlg).Interior.ColorIndex =3D xlNone
For Each ce In Range("a15:a" & derlg)
If Range("a" & ce.Row) & Range("a" & ce.Row + 1) =3D "" Then
Exit For
Range(Cells(ce.Row, 1), Cells(ce.Row,
3)).Interior.ColorIndex =3D 15 * (ce.Row Mod 2)
Next





ActiveWindow.DisplayZeros =3D False

ActiveSheet.PageSetup.PrintArea =3D ("$A$1:$C$" &
Range("A65536").End(xlUp).Row)
With ActiveSheet.PageSetup

.LeftMargin =3D Application.InchesToPoints(0.25)
.RightMargin =3D Application.InchesToPoints(0.25)
.TopMargin =3D Application.InchesToPoints(0.25)
.BottomMargin =3D Application.InchesToPoints(0.25)
.HeaderMargin =3D Application.InchesToPoints(0.3)
.FooterMargin =3D Application.InchesToPoints(0.3)
'.PrintQuality =3D 600
.Orientation =3D xlPortrait
'.PaperSize =3D xlPaperA4
.FirstPageNumber =3D xlAutomatic
.Order =3D xlDownThenOver
.Zoom =3D False
.FitToPagesWide =3D 1
.FitToPagesTall =3D 1
.PrintErrors =3D xlPrintErrorsDisplayed
End With
Suite1:
Worksheets("Transitory2").Select
Worksheets("Transitory2").Columns("B:B").Select
Selection.Delete Shift:=3DxlToLeft
Next I
Suite:

'Delete the unwanted sheets ("1" and "2" and "3" and "4" and "5"
and "6" (hall#)
'as well as 0pen and "Transitory1". Note that "Transitory2" is not
deleted
'as one wants to keep it to check that all companies were
processed (need to be empty)
'Note that On Error Resume Next allow to continue even a sheet
does not exist


'Dim c As Range
'For Each c In Sheets("Company Data").Range("B4:B500").Cells
'Select Case c
'Case "What is the Scheduler", "Instructions", "Fax Template",
"Country Data", "Company Data", "Country Appointments", "Company
Appointments", "Statistics", "EmailAllCountrySchedules",
"EmailAllCompanySchedules"
'on fait rien
'Case Else
'On Error Resume Next
'Application.DisplayAlerts =3D False
'ThisWorkbook.Sheets(c.Value).Delete
'Application.DisplayAlerts =3D True
'On Error GoTo 0
'End Select
'Next
'Delete the unwanted sheets 0pen, "Transitory2" and and
"Transitory3". Note that "Transitory2" is not deleted
'as one wants to keep it to check that all companies were
processed (need to be empty)
'Note that On Error Resume Next allow to continue even a sheet
does not exist


On Error Resume Next
SendKeys ("{ENTER}")
Sheets("Transitory3").Delete
On Error Resume Next
SendKeys ("{ENTER}")
Sheets("Transitory1").Delete

'Delete all sheets starting with "Sheet" and followed by something
e.g. "sheet1" "sheet 150" sheet"999" etc.
Application.DisplayAlerts =3D False
For Each S In Sheets
If S.Name Like "Sheet*" Then S.Delete
Next
Application.DisplayAlerts =3D True

'Move sheet "Country Appointments" and "Company Appointments"
Sheets("What is the Scheduler").Select
Sheets("What is the Scheduler").Move Before:=3DSheets(1)
Sheets("Instructions").Select
Sheets("Instructions").Move Before:=3DSheets(2)
Sheets("Fax Template").Select
Sheets("Fax Template").Move Before:=3DSheets(3)
Sheets("Country Data").Select
Sheets("Country Data").Move Before:=3DSheets(4)
Sheets("Company Data").Select
Sheets("Company Data").Move Before:=3DSheets(5)
Sheets("Country Appointments").Select
Sheets("Country Appointments").Move Before:=3DSheets(6)
Sheets("Company Appointments").Select
Sheets("Company Appointments").Move Before:=3DSheets(7)
Sheets("Statistics").Select
Sheets("Statistics").Move Before:=3DSheets(8)
Sheets("EmailAllCompanySchedules").Select
Sheets("EmailAllCompanySchedules").Move Before:=3DSheets(9)
Sheets("EmailAllCountrySchedules").Select
Sheets("EmailAllCountrySchedules").Move Before:=3DSheets(10)
Sheets("Transitory4").Select
Sheets("Transitory4").Move Before:=3DSheets(11)
Sheets("Transitory6").Select
Sheets("Transitory6").Move Before:=3DSheets(12)
Sheets("Transitory2").Select
Sheets("Transitory2").Move Before:=3DSheets(13)

Sheets("Company Appointments").Select
ActiveWorkbook.Protect Password:=3D"*****", Structure:=3DTrue,
Windows:=3DFalse
Range("B2").Select

'Sheets("Country Data").Select
'Sheets("Country Data").Move before:=3DSheets(3)
'Sheets("Country Appointments").Select
'Sheets("Country Appointments").Move before:=3DSheets(5)
'ActiveWindow.ScrollWorkbookTabs Position:=3DxlLast
'Sheets("Company Appointments").Select
'Sheets("Company Appointments").Move before:=3DSheets(6)
'ActiveWindow.ScrollWorkbookTabs Sheets:=3D-1
'Sheets("Company Appointments").Select

'Freeze 1 column and 1 row of "company appointments".
'ActiveCell("C2") is supposed to display the top part of the sheet
but does not work (need to be fixed)
Range("B2").Select
ActiveWorkbook.Unprotect Password:=3D"*****"
ActiveWindow.FreezePanes =3D True
'Range("C2").Activate
'Sheets("Country Appointments").Select


' This Macro below was added to create the Transitory6 sheet which
feed the EmailAllCompanySchedules template.

On Error Resume Next
SendKeys ("{ENTER}")
Sheets("Transitory5").Delete
Sheets.Add.Name =3D "Transitory5"
Sheets("Transitory6").Select
ActiveSheet.Unprotect Password:=3D"*****"
'Application.CutCopyMode =3D False
Cells.Select
Selection.ClearContents
Sheets("Company Data").Select
Range("A4:AJ503").Select
Selection.Copy
Sheets("Transitory5").Select
Range("C4").Select
Selection.PasteSpecial Paste:=3DxlPasteValues, Operation:=3DxlNone,
SkipBlanks _
:=3DFalse=
,
Transpose:=3DFalse
Cells.Select
Selection.Copy
Sheets("Transitory6").Select
ActiveSheet.Unprotect Password:=3D"*****"
Range("A1").Select
Selection.PasteSpecial Paste:=3DxlPasteValues, Operation:=3DxlNone,
SkipBlanks _
:=3DFalse=
,
Transpose:=3DFalse



'Delete all sheets starting with "Sheet" and followed by something
e.g. "sheet1" "sheet 150" sheet"999" etc.
Application.DisplayAlerts =3D False
For Each S In Sheets
If S.Name Like "Sheet*" Then S.Delete
Next
For Each S In Sheets
If S.Name Like "Feuil*" Then S.Delete
Next
Application.DisplayAlerts =3D True




' This Macro below was added to feed the EmailAllCompanySchedules
with the sheet tab names.

Sheets("EmailAllCompanySchedules").Select
ActiveSheet.Unprotect Password:=3D"*****"
Dim Ws As Worksheet, wb As Workbook, R As Range, Ig As Integer
Set wb =3D ActiveWorkbook
Set R =3D ActiveSheet.Range("C7")
Ig =3D 1
For Each Ws In wb.Worksheets
R.Cells(Ig, 1) =3D Ws.Name
Ig =3D Ig + 1
Next Ws


'Range("C21:C140").Select
'Selection.Copy
'Range("C7").Select
'ActiveSheet.Paste
'Range("C126:C141").Select
'Selection.Delete Shift:=3DxlUp


Range("C7:C21").Select
Selection.ClearContents
Range("C22:C139").Select
Selection.Copy
Range("C7").Select
ActiveSheet.Paste
Range("C127:C139").Select
Selection.ClearContents


Sheets("Transitory6").Select
ActiveSheet.Unprotect Password:=3D"*****"
Dim Wst As Worksheet
Dim mystr As String, cr As Range, It As Integer
For Each cr In [C4:C503]
mystr =3D ""
For It =3D 1 To Len(cr)
x =3D Mid(cr, It, 1)
If InStr("/?;*&:[]\", x) > 0 Then
mystr =3D mystr & "_"
Else
mystr =3D mystr & x
End If
Next It
cr.Offset(, -1) =3D mystr
Next cr
Range("A4").Select
ActiveCell.FormulaR1C1 =3D "=3DLEFT(RC[1],31)"
Range("A4").Select
Selection.AutoFill Destination:=3DRange("A4:A503"),
Type:=3DxlFillDefault

Cells.Select
Cells.EntireColumn.AutoFit
Selection.RowHeight =3D 15




Sheets("Transitory5").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Company Data").Select
Range("1:1,2:2,3:3,AJ:AJ").Select
Selection.Locked =3D True
Selection.FormulaHidden =3D False
ActiveSheet.Protect DrawingObjects:=3DTrue, Contents:=3DTrue,
Scenarios:=3DTrue _
, AllowFormattingCells:=3DTrue,
AllowFormattingColumns:=3DTrue, _
AllowFormattingRows:=3DTrue,
AllowInsertingHyperlinks:=3DTrue
Sheets("Company Appointments").Select
ActiveWorkbook.Save
ActiveWorkbook.Protect Password:=3D"*****", Structure:=3DTrue,
Windows:=3DFalse
Range("B2").Select
Sheets("Company Appointments").Protect Password:=3D"*****",
DrawingObjects:=3DTrue, Contents:=3DTrue, Scenarios:=3DTrue _
, AllowFormattingCells:=3DTrue,
AllowFormattingColumns:=3DTrue, _
AllowFormattingRows:=3DTrue,
AllowInsertingHyperlinks:=3DTrue

Sheets("Country Appointments").Protect Password:=3D"*****",
DrawingObjects:=3DTrue, Contents:=3DTrue, Scenarios:=3DTrue _
, AllowFormattingCells:=3DTrue,
AllowFormattingColumns:=3DTrue, _
AllowFormattingRows:=3DTrue,
AllowInsertingHyperlinks:=3DTrue

Sheets("EmailAllCompanySchedules").Select
ActiveSheet.Protect Password:=3D"*****", DrawingObjects:=3DTrue,
Contents:=3DTrue, Scenarios:=3DTrue _
, AllowFormattingCells:=3DTrue,
AllowFormattingColumns:=3DTrue, _
AllowFormattingRows:=3DTrue
Worksheets("EmailAllCompanySchedules").Select
Range("A8").Select
End Sub

Private Sub Workbook_WindowResize(ByVal Wn As Window)

If Wn.WindowState =3D xlMinimized Then
ThisWorkbook.Unprotect Password:=3D"*****"
Else
ThisWorkbook.Protect Password:=3D"*****", Structure:=3DTrue,
Windows:=3DFalse
End If

End Sub

1 réponse

Avatar
HD
bonjour,

Pas le temps de lire toute votre macro... mais une piste... optimisez votre
vba... il y'a de nombreux articles sur le sujet dont:
http://xcell05.free.fr/pages/prog/accvba.htm
http://www.info-3000.com/vbvba/conseiloptimisation.php

--
@+
HD