S
smoenra
I created a custom toolbar with two buttons. One button adds a blank ro
to the spreadsheet with proper formatting and the other removes a row.
I assigned a macro to each button. The problem is when I open th
template to create a new spreadsheet and click either of the buttons i
tries to open the last saved document created by this template to ru
the macro from. The custom toolbar is attached to the template. When
assign the macro to the button it is referenced as AddNewRow. After
create one document from the template and save then create a ne
template, that new template custom toolbar button is referencin
'C:\Documents and Settings\.....\test.xls'!addnewrow. Any thoughts?
Code:
Sub AddNewRow()
'
'Dim Row_Count As Integer
Dim pswrd
Dim QtyCell As String
Dim msg
Dim myRow As String
myRow = ActiveCell.Row
Range("B" & myRow).Select
If Not Selection.Interior.ColorIndex = xlNone Then
msg = "You've chosen to add a row in a locked area. " & Chr(13
& _
"Please select a different area to insert a row then tr
again."
response = MsgBox(msg, vbCritical)
GoTo 100
End If
pswrd = ""
ActiveSheet.Unprotect pswrd
'Row_Count = InputBox("Enter number of rows required.")
'Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(Row_Count - 1
0)).EntireRow.Insert
Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(0
0)).EntireRow.Insert
'myRow = ActiveCell.Row
'Range("B" & myRow).Select
Range(Selection, Selection.Offset(0, 4)).Select
Selection.Interior.ColorIndex = xlNone
Selection.RowHeight = 12.75
Selection.Locked = False
Selection.FormulaHidden = False
Selection.Borders(xlDiagonalDown).LineStyle = xlNone 'next many line
are for border formatting
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Font
.Name = "Arial"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
End With
Selection.Font.Bold = False
ActiveCell.Select
QtyCell = ActiveCell.Address
With Selection
.NumberFormat = "General"
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlTop
.WrapText = False
.Orientation = 0
.AddIndent = False
'.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveCell.Offset(0, 2).HorizontalAlignment = xlLeft 'des
alignment
ActiveCell.Offset(0, 2).WrapText = True 'desc wra
text
ActiveCell.Offset(0, 3).NumberFormat = "$#,##0.00"
'ListCell = ActiveCell.Offset(0, 3).Address
ActiveCell.Offset(0, 4).NumberFormat = "$#,##0.00"
ActiveCell.Offset(0, 4).Formula = "=" & QtyCell & "*"
ActiveCell.Offset(0, 3).Address
ActiveSheet.Protect pswrd, True, True, True
'
100 End Su
to the spreadsheet with proper formatting and the other removes a row.
I assigned a macro to each button. The problem is when I open th
template to create a new spreadsheet and click either of the buttons i
tries to open the last saved document created by this template to ru
the macro from. The custom toolbar is attached to the template. When
assign the macro to the button it is referenced as AddNewRow. After
create one document from the template and save then create a ne
template, that new template custom toolbar button is referencin
'C:\Documents and Settings\.....\test.xls'!addnewrow. Any thoughts?
Code:
Sub AddNewRow()
'
'Dim Row_Count As Integer
Dim pswrd
Dim QtyCell As String
Dim msg
Dim myRow As String
myRow = ActiveCell.Row
Range("B" & myRow).Select
If Not Selection.Interior.ColorIndex = xlNone Then
msg = "You've chosen to add a row in a locked area. " & Chr(13
& _
"Please select a different area to insert a row then tr
again."
response = MsgBox(msg, vbCritical)
GoTo 100
End If
pswrd = ""
ActiveSheet.Unprotect pswrd
'Row_Count = InputBox("Enter number of rows required.")
'Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(Row_Count - 1
0)).EntireRow.Insert
Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(0
0)).EntireRow.Insert
'myRow = ActiveCell.Row
'Range("B" & myRow).Select
Range(Selection, Selection.Offset(0, 4)).Select
Selection.Interior.ColorIndex = xlNone
Selection.RowHeight = 12.75
Selection.Locked = False
Selection.FormulaHidden = False
Selection.Borders(xlDiagonalDown).LineStyle = xlNone 'next many line
are for border formatting
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Font
.Name = "Arial"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = 1
End With
Selection.Font.Bold = False
ActiveCell.Select
QtyCell = ActiveCell.Address
With Selection
.NumberFormat = "General"
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlTop
.WrapText = False
.Orientation = 0
.AddIndent = False
'.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
ActiveCell.Offset(0, 2).HorizontalAlignment = xlLeft 'des
alignment
ActiveCell.Offset(0, 2).WrapText = True 'desc wra
text
ActiveCell.Offset(0, 3).NumberFormat = "$#,##0.00"
'ListCell = ActiveCell.Offset(0, 3).Address
ActiveCell.Offset(0, 4).NumberFormat = "$#,##0.00"
ActiveCell.Offset(0, 4).Formula = "=" & QtyCell & "*"
ActiveCell.Offset(0, 3).Address
ActiveSheet.Protect pswrd, True, True, True
'
100 End Su