I am formatting access data to excel worksheet and the portion of my code runs, but it is not hiding excel columns that I specify.
I am including the function below and highlighted code hiding the excel columns portion that does not hide the columns. I took the code generated by Excel when recording macro while performing this manually within excel.
Here is the function below. The hiding excel columns code is towards the bottom of the function higlighted in "red". Btw, I am generating multiple Excel workbooks with multiple tabs (sheets), so doing this manually is out of the question.
Any help is greatly appreciated.
Thank you.
David
I am including the function below and highlighted code hiding the excel columns portion that does not hide the columns. I took the code generated by Excel when recording macro while performing this manually within excel.
Here is the function below. The hiding excel columns code is towards the bottom of the function higlighted in "red". Btw, I am generating multiple Excel workbooks with multiple tabs (sheets), so doing this manually is out of the question.
Any help is greatly appreciated.
Thank you.
David
Code:
Public Function SendTQ2XLWbSheet(strTQName As String, strSheetName As String, strFilePath As String)
' strTQName is the name of the table or query you want to send to Excel
' strSheetName is the name of the sheet you want to send it to
' strFilePath is the name and path of the file you want to send this data into.
Dim rst As DAO.Recordset
Dim Apxl As Object
Dim xlWBk As Object
Dim xlWSh As Object
Dim fld As DAO.field
Dim FileExists As Boolean
Dim strPath As String
Const xlCenter As Long = -4108
Const xlBottom As Long = -4107
' On Error GoTo err_handler
FileExists = False
strPath = strFilePath
Set rst = CurrentDb.OpenRecordset(strTQName)
Set Apxl = CreateObject("Excel.Application")
' Check if Excel Workbook exists
If Not WorkBookExists(strPath) Then
' MsgBox "Excel Workbook doesn't exist and creating one!"
Set xlWBk = Apxl.Workbooks.Add
FileExists = False
' Check if Excel Worksheet name exists
If Not SheetExists(strSheetName, xlWBk) Then
' MsgBox "Excel Worksheet doesn't exist and creating one!"
Set xlWSh = xlWBk.Worksheets.Add
xlWSh.Name = strSheetName
' xlWBk.SaveAs strPath
' xlWBk.Worksheets.Add().Name = strSheetName
' Set xlWSh = xlWBk.Worksheets(strSheetName)
' xlWbk.Worksheets(strSheetName).Activate
Else
Set xlWSh = xlWBk.Worksheets(strSheetName)
' xlWSh.Activate
End If ' end to Check for Excel Worksheet
' When Workbook already exists setting workbook and worksheet
Else
Set xlWBk = Apxl.Workbooks.Open(strPath)
' Check if Excel Worksheet name exists
If Not SheetExists(strSheetName, xlWBk) Then
' MsgBox "Excel Worksheet doesn't exist and creating one!"
Set xlWSh = xlWBk.Worksheets.Add
xlWSh.Name = strSheetName
' xlWBk.Worksheets.Add().Name = strSheetName
' Set xlWSh = xlWBk.Worksheets(strSheetName)
' xlWbk.Worksheets(strSheetName).Activate
Else
Set xlWSh = xlWBk.Worksheets(strSheetName)
' xlWSh.Activate
End If ' end to Check for Excel Worksheet
' Set xlWSh = xlWBk.Worksheets(strSheetName)
FileExists = True
' xlWSh.Activate
End If ' end to Check for Excel Workbook
Apxl.Visible = False
xlWSh.Activate
rst.MoveFirst
'Get column headers
Dim i As Integer
Dim field As String
Dim rst2 As DAO.Recordset
Set rst2 = CurrentDb.OpenRecordset(strTQName)
With rst2
For i = 1 To .fields.Count
xlWSh.Cells(1, i) = .fields(i - 1).Name
Next i
End With
Set rst2 = Nothing
xlWSh.Range("A2").CopyFromRecordset rst
' end Get column headers
' LastRow = ActiveSheet.UsedRange.Rows.Count
' FORMAT SPEND PLAN WORKBOOK
'
' FormatAllData Macro
'
Dim LR As Integer
Dim Rng As String
' LR = ApXL.ActiveCell.SpecialCells(xlCellTypeLastCell).Row
' MsgBox ApXL.ActiveCell.SpecialCells(xlCellTypeLastCell).Row
' MsgBox ActiveSheet.UsedRange.Select
' MsgBox ActiveCell.CurrentRegion.Select
LR = xlWSh.Range("A:A").Find("*", xlWSh.Range("A1"), SearchDirection:=xlPrevious).Row
'MsgBox xlWSh.Range("A:A").Find("*", xlWSh.Range("A1"), SearchDirection:=xlPrevious).Row
Rng = "A1:BP" & CStr(LR)
' MsgBox Rng
xlWSh.Range(Rng).Select
With Apxl.Selection.Font
.Name = "Arial"
.Bold = False
.Size = 9
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontNone
End With
Apxl.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Apxl.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Apxl.Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Apxl.Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Apxl.Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Apxl.Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Apxl.Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Apxl.Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
xlWSh.Rows("1:1").Select
Apxl.Selection.Font.Bold = True
With Apxl.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Apxl.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
'
' YellowHeader Macro
'
xlWSh.Range("C1:F1").Select
With Apxl.Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 13434879
.TintAndShade = 0
.PatternTintAndShade = 0
End With
xlWSh.Range("N1:AW1").Select
With Apxl.Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 13434879
.TintAndShade = 0
.PatternTintAndShade = 0
End With
'
' ObjectClass Macro
'
' Calculate range
Rng = "B1:B" & CStr(LR)
xlWSh.Range(Rng).Select
With Apxl.Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -4.99893185216834E-02
.PatternTintAndShade = 0
End With
' Calculate range
Rng = "B2:B" & CStr(LR)
xlWSh.Range(Rng).Select
With Apxl.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
xlWSh.Range("B1").Select
With Apxl.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
'
' MissionCritical Macro
'
' Calculate range
Rng = "G1:G" & CStr(LR)
xlWSh.Range(Rng).Select
With Apxl.Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent4
.TintAndShade = 0.799981688894314
.PatternTintAndShade = 0
End With
With Apxl.Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
'
' VendorGreen Macro
'
' Calculate range
Rng = "H1:M" & CStr(LR)
xlWSh.Range(Rng).Select
With Apxl.Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent3
.TintAndShade = 0.799981688894314
.PatternTintAndShade = 0
End With
With Apxl.Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
xlWSh.Range("H1").Select
xlWSh.Columns("J:J").ColumnWidth = 11.71
xlWSh.Columns("L:L").ColumnWidth = 9.29
'
' CapitalYellow Macro
'
' Calculate range
Rng = "M1:M" & CStr(LR)
xlWSh.Range(Rng).Select
With Apxl.Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 65535
.TintAndShade = 0
.PatternTintAndShade = 0
End With
xlWSh.Columns("M:M").ColumnWidth = 9.43
'
' TotalSpend Macro
'
' Calculate range
Rng = "AX1:AX" & CStr(LR)
xlWSh.Range(Rng).Select
With Apxl.Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Apxl.Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent6
.TintAndShade = 0.599993896298105
.PatternTintAndShade = 0
End With
xlWSh.Columns("AX:AX").ColumnWidth = 16.71
xlWSh.Columns("AX:AX").Select
With Apxl.Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Apxl.Selection.ColumnWidth = 13.29
xlWSh.Range("AX1").Select
With Apxl.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
'
' FY12EOY Macro
'
' Calculate range
Rng = "AY1:AY" & CStr(LR)
xlWSh.Range(Rng).Select
With Apxl.Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent3
.TintAndShade = 0.599993896298105
.PatternTintAndShade = 0
End With
xlWSh.Range("AY1").Select
With Apxl.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
'
' QTRAUTH Macro
'
' Calculate range
Rng = "BA1:BA" & CStr(LR)
Rng = Rng & ",BD1:BD" & CStr(LR)
Rng = Rng & ",BG1:BG" & CStr(LR)
Rng = Rng & ",BJ1:BJ" & CStr(LR)
Rng = Rng & ",BM1:BM" & CStr(LR)
xlWSh.Range(Rng).Select
' Calculate range
Rng = "BA" & CStr(LR)
xlWSh.Range(Rng).Activate
With Apxl.Selection.Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent5
.TintAndShade = 0.399975585192419
.PatternTintAndShade = 0
End With
' Calculate range
Rng = "BM1:BM" & CStr(LR)
xlWSh.Range(Rng).Select
With Apxl.Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent5
.TintAndShade = 0.399975585192419
.PatternTintAndShade = 0
End With
'
' QTRPLAN Macro
'
xlWSh.Range("AZ1,BC1,BF1,BI1,BL1").Select
xlWSh.Range("BL1").Activate
With Apxl.Selection.Interior
.PatternColorIndex = xlAutomatic
.Color = 52479
.TintAndShade = 0
.PatternTintAndShade = 0
End With
' Calculate range
Rng = "AZ2:AZ" & CStr(LR)
Rng = Rng & ",BC2:BC" & CStr(LR)
Rng = Rng & ",BF2:BF" & CStr(LR)
Rng = Rng & ",BI2:BI" & CStr(LR)
Rng = Rng & ",BL2:BL" & CStr(LR)
xlWSh.Range(Rng).Select
' Calculate range
Rng = "BL" & CStr(LR)
xlWSh.Range(Rng).Activate
With Apxl.Selection.Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.149998474074526
.PatternTintAndShade = 0
End With
xlWSh.Range("BL1").Select
With Apxl.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
'
' TABDIV Macro
'
' Calculate range
Rng = "BO2:BP" & CStr(LR)
xlWSh.Range(Rng).Select
With Apxl.Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
'
' RecordInfo Macro
'
'
xlWSh.Columns("C:C").ColumnWidth = 15.14
xlWSh.Columns("C:C").Select
With Apxl.Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
xlWSh.Range("D1").Select
xlWSh.Columns("D:D").ColumnWidth = 19.86
xlWSh.Columns("D:D").Select
With Apxl.Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
xlWSh.Range("E1").Select
xlWSh.Columns("E:E").ColumnWidth = 25.71
xlWSh.Columns("E:E").Select
With Apxl.Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
xlWSh.Columns("F:F").Select
Apxl.Selection.ColumnWidth = 22.71
xlWSh.Columns("F:F").Select
With Apxl.Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
'
' ReqNum Macro
'
'
xlWSh.Columns("A:A").ColumnWidth = 14.71
' Calculate range
Rng = "A1:A" & CStr(LR)
xlWSh.Range(Rng).Select
With Apxl.Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent2
.TintAndShade = 0.799981688894314
.PatternTintAndShade = 0
End With
'
' Qtr Actual
'
' Calculate range
Rng = "BB1:BB" & CStr(LR)
Rng = Rng & ",BE1:BE" & CStr(LR)
Rng = Rng & ",BH1:BH" & CStr(LR)
Rng = Rng & ",BK1:BK" & CStr(LR)
Rng = Rng & ",BN1:BN" & CStr(LR)
xlWSh.Range(Rng).Select
With Apxl.Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 16737996
.TintAndShade = 0
.PatternTintAndShade = 0
End With
'
' ColumnFormat Macro
'
'
xlWSh.Columns("B:B").Select
Apxl.Selection.ColumnWidth = 8.43
With Apxl.Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Apxl.Selection.ColumnWidth = 7.57
Apxl.Selection.ColumnWidth = 6.86
xlWSh.Columns("G:G").Select
With Apxl.Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
xlWSh.Columns("AY:AY").Select
With Apxl.Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Apxl.Selection.ColumnWidth = 11.43
xlWSh.Columns("AJ:AJ").Select
With Apxl.Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Apxl.Selection.ColumnWidth = 11.14
xlWSh.Columns("AX:AX").Select
With Apxl.Selection
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Apxl.Selection.ColumnWidth = 13
'
' Dollars Macro
'
' Calculate range
Rng = "N2:BN" & CStr(LR)
xlWSh.Range(Rng).Select
Apxl.Selection.NumberFormat = "$#,##0.00"
'
[COLOR=#ff0000]' Hide Columns[/COLOR]
'
'
' xlWSh.Columns("Oct Auth", "Oct Actual", "Nov Auth", "Nov Plan").Select
' Apxl.Selection.EntireColumn.Hidden = True
' Columns("Y:Z").Select
' Selection.EntireColumn.Hidden = True
' xlWSh.Range( _
' "O:O,O:O,P:P,R:R,S:S,U:U,V:V,X:X,Y:Y,AA:AA,AB:AB,AD:AD,AE:AE,AG:AG,AH:AH,AJ:AJ,AK:AK,AM:AM,AN:AN,AP:AP,AQ:AQ,AS:AS,AT:AT,AV:AV,AW:AW,AZ:AZ,BB:BB,BC:BC" _
' ).Select
' xlWSh.Columns("O:P").Select
' xlWSh.Range("P1").Activate
' Apxl.Selection.EntireColumn.Hidden = True
[COLOR=#ff0000]Apxl.Union(xlWSh.Range( _[/COLOR]
[COLOR=#ff0000]"BJ:BJ,BL:BL,BM:BM,BO:BO,BP:BP,BX:BX,BY:BY,CE:CE,CD:CD,CC:CC,CB:CB,CA:CA,BZ:BZ,O:O,O:O,P:P,R:R,S:S,U:U,V:V,X:X,Y:Y,AA:AA,AB:AB,AD:AD,AE:AE,AG:AG,AH:AH,AJ:AJ,AK:AK,AM:AM,AN:AN" _[/COLOR]
[COLOR=#ff0000]), xlWSh.Range( _[/COLOR]
[COLOR=#ff0000]"AP:AP,AQ:AQ,AS:AS,AT:AT,AV:AV,AW:AW,AZ:AZ,BB:BB,BC:BC,BD:BD,BF:BF,BG:BG,BI:BI" _[/COLOR]
[COLOR=#ff0000])).Select[/COLOR]
[COLOR=#ff0000]xlWSh.Range("BZ1").Activate[/COLOR]
[COLOR=#ff0000]Apxl.Selection.EntireColumn.Hidden = True[/COLOR]
'
' UnHide Columns
'
'
' Columns("C:F").Select
' Selection.EntireColumn.Hidden = False
'
' DarkUnderline Macro
'
' Calculate range
Rng = "A1:BP" & CStr(LR)
xlWSh.Range(Rng).Select
Apxl.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Apxl.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Apxl.Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Apxl.Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Apxl.Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Apxl.Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Apxl.Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Apxl.Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
' Calculate range
Rng = "A2:BP" & CStr(LR)
xlWSh.Range(Rng).Select
Apxl.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Apxl.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Apxl.Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Apxl.Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Apxl.Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Apxl.Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlMedium
End With
With Apxl.Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Apxl.Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
' Call Function to delete sheet 1, 2, & 3 tabs
Call DeleteTabs(Apxl, xlWBk)
' selects all of the cells
Apxl.ActiveSheet.Cells.Select
' does the "autofit" for all columns
Apxl.ActiveSheet.Cells.EntireColumn.AutoFit
'
' Select cells to protect ... specifically the calculated fields
'
' Calculate range
Rng = "A1:BP1, A2:A" & CStr(LR) & " , AX2:BN" & CStr(LR)
xlWSh.Cells.Locked = False
xlWSh.Range(Rng).Locked = True
Apxl.ActiveSheet.Protect Password:="Password"
' selects the first cell to unselect all cells
xlWSh.Range("A1").Select
'Save the Workbook and Quit Excel
If FileExists Then
xlWBk.Close savechanges:=True
Else
xlWBk.SaveAs strPath
End If ' ending checking for saving workbook
rst.Close
Apxl.Quit
Set xlWSh = Nothing
Set xlWBk = Nothing
Set Apxl = Nothing
Set rst = Nothing
' Application.Quit this kills excel and access the same time... not good
Exit_SendTQ2XLWbSheet:
Exit Function
err_handler:
DoCmd.SetWarnings True
MsgBox Err.Description, vbExclamation, Err.Number
Resume Exit_SendTQ2XLWbSheet
End Function
Last edited: