twoodsmall79
New Member
- Joined
- Jul 18, 2014
- Messages
- 18
I have been searching all over with no luck so far. From Access I have the below code that updates a couple fields and fixes a number stored as text issue from a report downloaded daily that is ultimately part of a linked table. When I run this code the first time I get no errors but only the Cell names get updated. The second (or third) time I run this code the number stored as text issues are corrected. Any ideas why this is happening and how to prevent?
Code:
Sub AccrualBalance_Update()
Dim MySheetPath As String
Dim Xl As Excel.Application
Dim XlBook As Excel.Workbook
Dim XlSheet As Excel.Worksheet
MySheetPath = "H:\Agreement Balances.xlsx"
Set Xl = CreateObject("Excel.Application")
Set XlBook = GetObject(MySheetPath)
Set XlSheet = XlBook.Worksheets(1)
XlSheet.Range("A1") = "Sales Organization"
XlSheet.Range("B1") = "SoldToNum"
XlSheet.Range("C1") = "Agreement Type"
XlSheet.Range("D1") = "AgreementNum"
XlSheet.Range("L1") = "EndBal"
With XlSheet.UsedRange
.Value = .Value
End With
XlSheet.Range("A:B", "D:D").NumberFormat = "0"
XlBook.Windows(1).Visible = True
XlBook.Save
XlBook.Close
Xl.Quit
End Sub