View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Stephen Bullen[_3_] Stephen Bullen[_3_] is offline
external usenet poster
 
Posts: 74
Default The old application.quit problem

Hi Hafeez,

Public Sub formatWorkbook(ByRef XL As Excel.Application,
ByVal strRangeName As String, _
ByRef FormatRange As Excel.Range)
'Copies format of named range to selection
XL.Goto (strRangeName)
If (Selection.Row = FormatRange.Row) Then
Exit Sub
End If

sht.Cells(1, 1).Select
XL.Goto (strRangeName)
Selection.Copy
FormatRange.Select
FormatRange.PasteSpecial xlPasteFormats, , False, False
XL.ActiveSheet.Cells(1, 1).Select
End Sub

Specifically at "Selection.Row"


Whenever you use any of Excel's 'global' objects, such as Cells,
Selection etc, you must prefix them with the instance of Excel you're
using:

Public Sub formatWorkbook(ByRef XL As Excel.Application,
ByVal strRangeName As String, _
ByRef FormatRange As Excel.Range)
'Copies format of named range to selection
XL.Goto (strRangeName)
If (XL.Selection.Row = FormatRange.Row) Then
Exit Sub
End If

sht.Cells(1, 1).Select
XL.Goto (strRangeName)
XL.Selection.Copy
FormatRange.Select
FormatRange.PasteSpecial xlPasteFormats, , False, False
XL.ActiveSheet.Cells(1, 1).Select
End Sub



Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.ie