UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
> Code Automating Excel Fails Alternate Runs, Access 2016    
 
   
expatriate
post Nov 14 2019, 04:22 AM
Post#1



Posts: 416
Joined: 23-April 10
From: Thailand


Hi,
This works the first time. 2nd time fails as indicated. Rinse and repeat. Perhaps I should have a qualifier for "selection"? But it works the first time(?). Beats me frown.gif

QUOTE
Sub test()

Dim xlApp As excel.Application
Dim xlBook As excel.Workbook
Dim xlSheet As excel.Worksheet
Dim ExcelWkb2 As String
Dim range As excel.range

ExcelWkb2 = CurrentProject.Path & "\Reports\AllDevices4Excel.csv"
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.Workbooks.Open(ExcelWkb2, 0, False)
xlBook.Worksheets(1).Cells.EntireColumn.AutoFit
Set xlSheet = xlBook.Worksheets(1)
xlSheet.range("a5:I55").Select
Set range = Selection
With range.FormatConditions.Add(Type:=xlExpression, Formula1:="=MOD(ROW(),2)=0")
'>>Object variable or With block variable not set

.Interior.Color = RGB(208, 216, 232)
.Borders.LineStyle = xlContinuous
.Borders.ThemeColor = 1
.Borders.Weight = xlThin
End With

xlBook.Close savechanges:=False
xlApp.Quit

Set xlBook = Nothing
Set xlApp = Nothing
Set xlSheet = nothing
End Sub
Go to the top of the page
 

Posts in this topic



Custom Search


RSSSearch   Top   Lo-Fi    1st April 2020 - 03:48 AM