Good morning
I have a piece of code which creates a spreadsheet using acOutputQuery
The coee then opens the spreadsheet and formats .activesheet .
Finally I want to turn the filter to 'on' for the spreadsheet but am struggling with the line of code
I have tried
objapp.activeworksheet.FilterMode = True
then
objapp.activeworksheet.autofiltermode=true
And various other versions where I have repalced .activeworksheet with the sheet name but I get various errors saying object does not support this property or method runtime 438
Could someone please point me a direction where I can solve this problem
I have included the full code below
Dim objapp As Object
Dim olapp As Object
Dim olmsg As Object
Dim Heading As String
Dim Orient As String
Dim RepeatRows As String
Dim strToday As String
Set objapp = CreateObject("excel.application")
Dim strFileNameASB5South As String
Dim olfileloc As Variant
Dim olfileloc1 As Variant
Set olapp = CreateObject("outlook.application")
Set olmsg = olapp.CreateItem(olMailItem)
Dim strQueryName As String
strToday = Format(Now, "dd-mm-yy hh-nn")
strQueryName = "qryASB5NotSentSouth"
strFileNameASB5South = "z:\ASB5NotSentFiles\Daily Update South" & " " & strToday & ".xlsx"
DoCmd.OutputTo acOutputQuery, strQueryName, acFormatXLSX, strFileNameASB5South, False
strQueryName = ""
Orient = "L"
RepeatRows = "$1:$1"
objapp.Visible = True
Set ws = objapp.Workbooks.Open(strFileNameASB5South, True, False)
With ws
With objapp.ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = Heading
.RightHeader = "Page &P of &N"
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = ws.Application.InchesToPoints(0.15)
.RightMargin = ws.Application.InchesToPoints(0.15)
.TopMargin = ws.Application.InchesToPoints(0.5)
.BottomMargin = ws.Application.InchesToPoints(1)
.HeaderMargin = ws.Application.InchesToPoints(0.5)
.FooterMargin = ws.Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = Excel.xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = True
.CenterVertically = False
If Orient = "P" Then myOrient = Excel.xlPortrait Else If Orient = "L" Then myOrient = Excel.xlLandscape
.Orientation = myOrient
.Draft = False
.FirstPageNumber = Excel.xlAutomatic
.Order = Excel.xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
.PrintTitleRows = RepeatRows
End With
With objapp.ActiveSheet.Range("A1:AA1")
.WrapText = True
End With
Set cellrange = objapp.Range("J2
200")
For Each Cell In cellrange
If Cell.Value = "Yes" Then
Cell.Interior.ColorIndex = 4
End If
If Cell.Value = "No" Then
Cell.Interior.ColorIndex = 3
End If
Next
objapp.activeworksheet.FilterMode = True
End With
Thanks
Rnutts
I have a piece of code which creates a spreadsheet using acOutputQuery
The coee then opens the spreadsheet and formats .activesheet .
Finally I want to turn the filter to 'on' for the spreadsheet but am struggling with the line of code
I have tried
objapp.activeworksheet.FilterMode = True
then
objapp.activeworksheet.autofiltermode=true
And various other versions where I have repalced .activeworksheet with the sheet name but I get various errors saying object does not support this property or method runtime 438
Could someone please point me a direction where I can solve this problem
I have included the full code below
Dim objapp As Object
Dim olapp As Object
Dim olmsg As Object
Dim Heading As String
Dim Orient As String
Dim RepeatRows As String
Dim strToday As String
Set objapp = CreateObject("excel.application")
Dim strFileNameASB5South As String
Dim olfileloc As Variant
Dim olfileloc1 As Variant
Set olapp = CreateObject("outlook.application")
Set olmsg = olapp.CreateItem(olMailItem)
Dim strQueryName As String
strToday = Format(Now, "dd-mm-yy hh-nn")
strQueryName = "qryASB5NotSentSouth"
strFileNameASB5South = "z:\ASB5NotSentFiles\Daily Update South" & " " & strToday & ".xlsx"
DoCmd.OutputTo acOutputQuery, strQueryName, acFormatXLSX, strFileNameASB5South, False
strQueryName = ""
Orient = "L"
RepeatRows = "$1:$1"
objapp.Visible = True
Set ws = objapp.Workbooks.Open(strFileNameASB5South, True, False)
With ws
With objapp.ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = Heading
.RightHeader = "Page &P of &N"
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = ws.Application.InchesToPoints(0.15)
.RightMargin = ws.Application.InchesToPoints(0.15)
.TopMargin = ws.Application.InchesToPoints(0.5)
.BottomMargin = ws.Application.InchesToPoints(1)
.HeaderMargin = ws.Application.InchesToPoints(0.5)
.FooterMargin = ws.Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = False
.PrintComments = Excel.xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = True
.CenterVertically = False
If Orient = "P" Then myOrient = Excel.xlPortrait Else If Orient = "L" Then myOrient = Excel.xlLandscape
.Orientation = myOrient
.Draft = False
.FirstPageNumber = Excel.xlAutomatic
.Order = Excel.xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
.PrintTitleRows = RepeatRows
End With
With objapp.ActiveSheet.Range("A1:AA1")
.WrapText = True
End With
Set cellrange = objapp.Range("J2

For Each Cell In cellrange
If Cell.Value = "Yes" Then
Cell.Interior.ColorIndex = 4
End If
If Cell.Value = "No" Then
Cell.Interior.ColorIndex = 3
End If
Next
objapp.activeworksheet.FilterMode = True
End With
Thanks
Rnutts