Jason Lee Hayes
Active member
- Local time
- Today, 16:31
- Joined
- Jul 25, 2020
- Messages
- 196
I have created an Excel 2016 spreadsheet to represent some statistics. (My Excel skills are VERY limited)
It contains 4 rows which represent numbers and when i adjust these numbers the graphs to the right adjust accordingly..
The numbers i wish to populate from an Access Table
My idea is that i have my MS Access Dbase open & when i click a button on my access form it opens the Excel sheet in the background, populates the columns using .range command and rows automatically then refreshed in Excel sheet.
Some things:-
I am using Office 2016 environment & If i open the Excel sheet directly; it opens and i can change the figures which then change the graphs.
I have a reference set to MS ExceI 16 Object Library set & did have this part working in that if i opened the excel sheet and made the changes then try viewing it would crash I got round this by opening the excel sheet, making the changes, closing the excel file then opening for viewing
Here is my code which i have pieced together which did sort of work:-
' open excel and update cell values using .range method
Dim appExcel As Excel.Application
Dim wbook As Excel.Workbook
Dim wsheet As Excel.Worksheet
17030 Set appExcel = New Excel.Application
17040 appExcel.Visible = False
17050 Set wbook = appExcel.Workbooks.Open("C:\Paradox CCTV Support DataBase\InViewDashboard.xlsm")
17060 Set wsheet = wbook.Worksheets("Sheet1")
wbook.Application.DisplayAlerts = True
wbook.Application.IgnoreRemoteRequests = True
With wsheet
' example data used to populate row value
.Range("B9").value = "SC 0001" ' Site Card ID
.Range("C9").value = "10" ' Faults Reported
.Range("D9").value = "5" ' Faults Resolved
.Range("E9").value = "5" ' Faults Outstanding
.Range("F9").value = "5" ' Days Took
.Range("B10").value = "SC 0002" ' Site Card ID
.Range("C10").value = "12" ' Faults Reported
.Range("D10").value = "3" ' Faults Resolved
.Range("E10").value = "9" ' Faults Outstanding
.Range("F10").value = "7" ' Days Took
End With
17070 wbook.Save
17080 Set wsheet = Nothing
17090 wbook.Close True
17100 Set wbook = Nothing
17110 Set appExcel = Nothing
'open file again in visible mode
17120 Set appExcel = New Excel.Application
17130 appExcel.Visible = True
17140 Set wbook = appExcel.Workbooks.Open("C:\Paradox CCTV Support DataBase\InViewDashboard.xlsx")
17150 Set wsheet = wbook.Worksheets("Sheet1")
End Sub
I don't expect the work to be done for me as i like to learn and understand myself but i would appreciate if someone who knows Access VBA & Excel to quickly look over the code and suggest and changes/fixes...
Thanks in advance
Regards,
Jason
Sorry if I've posted in wrong place, not sure if Access or Excel related (Or both)
It contains 4 rows which represent numbers and when i adjust these numbers the graphs to the right adjust accordingly..
The numbers i wish to populate from an Access Table
My idea is that i have my MS Access Dbase open & when i click a button on my access form it opens the Excel sheet in the background, populates the columns using .range command and rows automatically then refreshed in Excel sheet.
Some things:-
I am using Office 2016 environment & If i open the Excel sheet directly; it opens and i can change the figures which then change the graphs.
I have a reference set to MS ExceI 16 Object Library set & did have this part working in that if i opened the excel sheet and made the changes then try viewing it would crash I got round this by opening the excel sheet, making the changes, closing the excel file then opening for viewing
Here is my code which i have pieced together which did sort of work:-
' open excel and update cell values using .range method
Dim appExcel As Excel.Application
Dim wbook As Excel.Workbook
Dim wsheet As Excel.Worksheet
17030 Set appExcel = New Excel.Application
17040 appExcel.Visible = False
17050 Set wbook = appExcel.Workbooks.Open("C:\Paradox CCTV Support DataBase\InViewDashboard.xlsm")
17060 Set wsheet = wbook.Worksheets("Sheet1")
wbook.Application.DisplayAlerts = True
wbook.Application.IgnoreRemoteRequests = True
With wsheet
' example data used to populate row value
.Range("B9").value = "SC 0001" ' Site Card ID
.Range("C9").value = "10" ' Faults Reported
.Range("D9").value = "5" ' Faults Resolved
.Range("E9").value = "5" ' Faults Outstanding
.Range("F9").value = "5" ' Days Took
.Range("B10").value = "SC 0002" ' Site Card ID
.Range("C10").value = "12" ' Faults Reported
.Range("D10").value = "3" ' Faults Resolved
.Range("E10").value = "9" ' Faults Outstanding
.Range("F10").value = "7" ' Days Took
End With
17070 wbook.Save
17080 Set wsheet = Nothing
17090 wbook.Close True
17100 Set wbook = Nothing
17110 Set appExcel = Nothing
'open file again in visible mode
17120 Set appExcel = New Excel.Application
17130 appExcel.Visible = True
17140 Set wbook = appExcel.Workbooks.Open("C:\Paradox CCTV Support DataBase\InViewDashboard.xlsx")
17150 Set wsheet = wbook.Worksheets("Sheet1")
End Sub
I don't expect the work to be done for me as i like to learn and understand myself but i would appreciate if someone who knows Access VBA & Excel to quickly look over the code and suggest and changes/fixes...
Thanks in advance
Regards,
Jason
Sorry if I've posted in wrong place, not sure if Access or Excel related (Or both)