gakiss2
Registered User.
- Local time
- Today, 12:20
- Joined
- Nov 21, 2018
- Messages
- 168
I want to send some data from a query to a macro enabled (.xlsm) Excel workbook and then open it (the excel workbook) from access. I have had to do some work arounds that don't make sense just to get as far as I have gotten so I would be happy to hear the 'right' way to do it so I don't need all these gymnastics AND I ultimately can't get it to work. I guess this is technically an Access problem but it does involve Excel (at least to the extent that I can't seem to get done what I need from Access). I hope it is OK to bring Excel in to the conversation as well, at least it is all VBA.
I first tried to export the data from Access to the Excel but I had lots of issues and finally got limited success by exporting to a non macro enabled (.xlsx) workbook. Which helps because if I do that then I can then just open the macro enabled excel from access and then transfer the data using the "on open" procedure in the macro enabled excel sheet. I know I'm getting dizzy just describing it but that is what has gotten me as far as I am. And why I thought it would be best to get help here because I don't know why I can't push some query data to a macro enabled workbook. If I (we) can do that then I don't have to do anything (complicated) in the Excel. Its just a smattering of data so its super easy to then get the data to the sheet and cells in Excel that are needed. Here is the data:
The Excel error message is 'out of range' which I can't figure but not sure that is relevant to the Access discussion. But, again, it seems if this is done correctly from Access then Excel doesn't need to be a part of the discussion.
and the code I have now in Access:
I tried TransferSpreadsheet and had lots of issues. I wouldn't transfer into the enabled sheet even though I picked acExcel12Xml format (that's not the exact format syntax). I couldn't even file a format for enabled sheets with OutputTo. I even had trouble just opening the dang excels until I went to App.. Hyperlink. In some trys the file being outputted to got corrupted and couldn't open, the error messages hinted at the data format didn't match up with the extension of the file.
Here is the (gymnastics ridden) Excel Code:
Private Sub Workbook_Open()
Dim dev As Worksheet
Set dev = Sheet1
Dim eng As Worksheet
Set eng = Sheet6
' Workbooks.Open "C:\Users\gkissick\Desktop\DeviationFormData.xlsx"
MsgBox "Wait"
eng.Unprotect "LooseNuts"
Workbooks("C:\Users\gkissick\Desktop\DeviationFormData.xlsx").Worksheets("qryDEV").Range("A2:E2").Copy _
ThisWorkbook.Worksheets("Engine").Range("K1:O1")
' Workbooks("C:\Users\gkissick\Desktop\DeviationFormData.xlsx").Worksheets("qryDEV").Range("A2
9").Copy _
' Workbooks("C:\Users\gkissick\Desktop\DeviationFormSBQD.xlsm").Worksheets("Engine").Range("K1")
'
' Below Code works fine ' its not part of this issue
Sheets("Deviation Form").Range("A1").Select
Set sh = ThisWorkbook.Sheets("Deviation Form") '
sh.Unprotect "LooseNuts"
Sheets("Deviation Form").Range("B33") = Null
sh.Protect "LooseNuts", UserInterfaceOnly:=True
Sheets("Deviation Form").TglLock = True
Sheets("Deviation Form").TglLock.Visible = False
Application.Wait Now + TimeValue("00:00:03")
' Unload ufWelcom
End Sub
I tried to upload the Excel but the site won't let me. I really don't think there is anything other than the above that would matter. it had all worked with manual entry instead of getting that from Access. The point of this exercise is that these excel sheets are kicked off from the creation of a record in the Database and this process give a jump start by pushing the data that is shared between them into the excel sheet.
I have been grinding on this one for a few hours now and I am stuck. Thanks for your help.
I first tried to export the data from Access to the Excel but I had lots of issues and finally got limited success by exporting to a non macro enabled (.xlsx) workbook. Which helps because if I do that then I can then just open the macro enabled excel from access and then transfer the data using the "on open" procedure in the macro enabled excel sheet. I know I'm getting dizzy just describing it but that is what has gotten me as far as I am. And why I thought it would be best to get help here because I don't know why I can't push some query data to a macro enabled workbook. If I (we) can do that then I don't have to do anything (complicated) in the Excel. Its just a smattering of data so its super easy to then get the data to the sheet and cells in Excel that are needed. Here is the data:
Title | PartNum | AssignedVendor | SQEName | NewLBTrackNo |
title | ghir | AKG | Gary Kissick | DEV-GK-20-130 |
The Excel error message is 'out of range' which I can't figure but not sure that is relevant to the Access discussion. But, again, it seems if this is done correctly from Access then Excel doesn't need to be a part of the discussion.
and the code I have now in Access:
Code:
Private Sub cmdSendDev_Click()
Dim wb As Workbook
' Module 5 contains some code that could be converted to pull the DEV template
' out of an attachment in tblFormAttach
' "C:\Users\gkissick\Desktop\DeviationFormSBQD.xlsm"
' Either open DEV template then import from this DB or export to DEV template then
' the data to go to the Deviation is in qryDEV
DoCmd.OutputTo acOutputQuery, "qryDEV", acFormatXLSX, "C:\Users\gkissick\Desktop\DeviationFormData.xlsx"
' DoCmd.OutputTo acOutputQuery, "qryDEV", acFormatXLSB, "C:\Users\gkissick\Desktop\DeviationFormSBQD.xlsm"
Application.FollowHyperlink "C:\Users\gkissick\Desktop\DeviationFormData.xlsx"
Application.FollowHyperlink "C:\Users\gkissick\Desktop\DeviationFormSBQD.xlsm"
End Sub
I tried TransferSpreadsheet and had lots of issues. I wouldn't transfer into the enabled sheet even though I picked acExcel12Xml format (that's not the exact format syntax). I couldn't even file a format for enabled sheets with OutputTo. I even had trouble just opening the dang excels until I went to App.. Hyperlink. In some trys the file being outputted to got corrupted and couldn't open, the error messages hinted at the data format didn't match up with the extension of the file.
Here is the (gymnastics ridden) Excel Code:
Private Sub Workbook_Open()
Dim dev As Worksheet
Set dev = Sheet1
Dim eng As Worksheet
Set eng = Sheet6
' Workbooks.Open "C:\Users\gkissick\Desktop\DeviationFormData.xlsx"
MsgBox "Wait"
eng.Unprotect "LooseNuts"
Workbooks("C:\Users\gkissick\Desktop\DeviationFormData.xlsx").Worksheets("qryDEV").Range("A2:E2").Copy _
ThisWorkbook.Worksheets("Engine").Range("K1:O1")
' Workbooks("C:\Users\gkissick\Desktop\DeviationFormData.xlsx").Worksheets("qryDEV").Range("A2

' Workbooks("C:\Users\gkissick\Desktop\DeviationFormSBQD.xlsm").Worksheets("Engine").Range("K1")
'
' Below Code works fine ' its not part of this issue
Sheets("Deviation Form").Range("A1").Select
Set sh = ThisWorkbook.Sheets("Deviation Form") '
sh.Unprotect "LooseNuts"
Sheets("Deviation Form").Range("B33") = Null
sh.Protect "LooseNuts", UserInterfaceOnly:=True
Sheets("Deviation Form").TglLock = True
Sheets("Deviation Form").TglLock.Visible = False
Application.Wait Now + TimeValue("00:00:03")
' Unload ufWelcom
End Sub
I tried to upload the Excel but the site won't let me. I really don't think there is anything other than the above that would matter. it had all worked with manual entry instead of getting that from Access. The point of this exercise is that these excel sheets are kicked off from the creation of a record in the Database and this process give a jump start by pushing the data that is shared between them into the excel sheet.
I have been grinding on this one for a few hours now and I am stuck. Thanks for your help.