T
trevorC via AccessMonster.com
Hi All,
I'm trying to create a list in excel "To stop people from un-sorting the
data". I'm trying to do this using VBA, so far i have created my spreadsheet
and added titles, sub totals and the data from several access queries, then
formated the sheet with borders, colors and cell alignment and sizes. I can
then select the area that i want for my List including headers, but the code
won't create a list.
the code we copied from an excel macro after creating a list. I have tried
several way of referencing the selection but it won't work. My other code was
also made like this and it all works ok as listed.
Code sample:
Dim Excel_Application As Excel.Application
Dim Excel_Workbook As Excel.Workbook
Dim Current_Worksheet As Excel.Worksheet
Set Excel_Workbook = GetObject(gg)
Set Excel_Application = Excel_Workbook.Parent
Excel_Workbook.Worksheets(1).Name = "Transfer Details"
Set Current_Worksheet = Excel_Workbook.Worksheets("Transfer Details")
Excel_Application.WindowState = xlMinimized
Excel_Application.Visible = True
Excel_Workbook.Windows(1).Visible = True
Current_Worksheet.Rows("1:1").Insert Shift:=xlDown
With selection
Current_Worksheet.Range("C55").MergeCells = True
End With
DoCmd.GoToRecord , , acNext
Next i
Current_Worksheet.Rows("5:5").Select
With selection
Current_Worksheet.Rows("5:5").Delete Shift:=xlUp
End With
Current_Worksheet.Range("B3:E4").Select
With selection
Current_Worksheet.Range("B3:E4").HorizontalAlignment = xlCenter
Current_Worksheet.Range("B3:E3").MergeCells = True
Current_Worksheet.Range("B3:E4").Font.Bold = True
End With
rng1 = "$A$11:$O$" & (RC + 11)
Current_Worksheet.Range(rng1).Select
With selection
Current_Worksheet.Range(rng1).ListObjects.Add(xlSrcRange, Range(rng1), ,
xlYes).Name = "List1"
End With
Excel_Workbook.Save
Excel_Application.Quit
I cant get this line of code to work
.ListObjects.Add(xlSrcRange, Range(rng1), , xlYes).Name = "List1"
all of the other code works fine
All help is appreciated.
regards
TrevorC
I'm trying to create a list in excel "To stop people from un-sorting the
data". I'm trying to do this using VBA, so far i have created my spreadsheet
and added titles, sub totals and the data from several access queries, then
formated the sheet with borders, colors and cell alignment and sizes. I can
then select the area that i want for my List including headers, but the code
won't create a list.
the code we copied from an excel macro after creating a list. I have tried
several way of referencing the selection but it won't work. My other code was
also made like this and it all works ok as listed.
Code sample:
Dim Excel_Application As Excel.Application
Dim Excel_Workbook As Excel.Workbook
Dim Current_Worksheet As Excel.Worksheet
Set Excel_Workbook = GetObject(gg)
Set Excel_Application = Excel_Workbook.Parent
Excel_Workbook.Worksheets(1).Name = "Transfer Details"
Set Current_Worksheet = Excel_Workbook.Worksheets("Transfer Details")
Excel_Application.WindowState = xlMinimized
Excel_Application.Visible = True
Excel_Workbook.Windows(1).Visible = True
Current_Worksheet.Rows("1:1").Insert Shift:=xlDown
With selection
Current_Worksheet.Range("C55").MergeCells = True
End With
DoCmd.GoToRecord , , acNext
Next i
Current_Worksheet.Rows("5:5").Select
With selection
Current_Worksheet.Rows("5:5").Delete Shift:=xlUp
End With
Current_Worksheet.Range("B3:E4").Select
With selection
Current_Worksheet.Range("B3:E4").HorizontalAlignment = xlCenter
Current_Worksheet.Range("B3:E3").MergeCells = True
Current_Worksheet.Range("B3:E4").Font.Bold = True
End With
rng1 = "$A$11:$O$" & (RC + 11)
Current_Worksheet.Range(rng1).Select
With selection
Current_Worksheet.Range(rng1).ListObjects.Add(xlSrcRange, Range(rng1), ,
xlYes).Name = "List1"
End With
Excel_Workbook.Save
Excel_Application.Quit
I cant get this line of code to work
.ListObjects.Add(xlSrcRange, Range(rng1), , xlYes).Name = "List1"
all of the other code works fine
All help is appreciated.
regards
TrevorC