Page 2 of 2 FirstFirst 12
Results 16 to 30 of 30
  1. #16
    ragsgold is offline Access & Excel Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2009
    Location
    Denver,CO
    Posts
    51


    Quote Originally Posted by June7 View Post
    I got this to work.


    Code in Excel general module:

    Sub myMacro()
    Worksheets("Sheet1").Range("A1") = "Start"
    MsgBox "Done"
    Worksheets("Sheet1").Range("A1") = "Done"
    End Sub


    Code in Access general module:

    Public Sub elxwrk()
    Dim oExcel As Excel.Application
    Set oExcel = CreateObject("Excel.Application")
    oExcel.Workbooks.Open ("C:\Temp\Book1.xlsm")
    oExcel.Run "myMacro"
    Do While Not oExcel.Worksheets("Sheet1").Range("A1") = "Done"
    DoEvents
    Loop
    oExcel.Worksheets("Sheet1").Range("A1") = "Start"
    oExcel.Quit
    End Sub
    Ok here i what I did or changed

    in my Excel

    Sub myMacro()
    Worksheets("Pivot").Range("D1") = "Start"
    ActiveWorkbook.refreshall
    MsgBox "Done"
    Worksheets("Pivot").Range("D1") = "Done"
    End Sub

    the above works very well no issues.

    Next in my Access Module

    Public Sub elxwrk()
    Dim oExcel As Excel.Application
    Set oExcel = CreateObject("Excel.Application")
    oExcel.Workbooks.Open ("Y:\nara\Access DB Projects\Infinium Actual payroll DB\Reports\Infinium Payroll Report1.xlsm")
    oExcel.Run "myMacro"
    Do While Not oExcel.Worksheets("pivot").Range("D1") = "Done"
    DoEvents
    Loop
    oExcel.Worksheets("pivot").Range("D1") = "Start"
    oExcel.Quit
    End Sub

    when i execute it i get an error at line - Public Sub elxwrk() "compile error user defined type not defined"

    what do you think i did incorrectly in the Access code here ?

  2. #17
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Have you set a VBA reference in Access for Excel 12.0 Object Library?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #18
    ragsgold is offline Access & Excel Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2009
    Location
    Denver,CO
    Posts
    51
    Quote Originally Posted by June7 View Post
    Have you set a VBA reference in Acces for Excel 12.0 Object Library?
    I havnt set anything like that i could remember of where can i check that ...do you mean in the ODBC driver or Regedit ? But i have other access databases where I am using VBA codes interfacing excel is this file specific

  4. #19
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Yes, it is file specific. From the VBA editor select Tools>References>scroll until you find the library and check it:

    Microsoft Excel 12.0 Object Library


    The MsgBox in the Excel code is not necessary. I just used it as a debug/testing tool.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #20
    alcapps is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2012
    Posts
    292
    no problem.. I hope that works for you..

  6. #21
    ragsgold is offline Access & Excel Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2009
    Location
    Denver,CO
    Posts
    51
    Quote Originally Posted by June7 View Post
    Yes, it is file specific. From the VBA editor select Tools>References>scroll until you find the library and check it:

    Microsoft Excel 12.0 Object Library


    The MsgBox in the Excel code is not necessary. I just used it as a debug/testing tool.
    Yes i just checked and it is selected or checked

  7. #22
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The code works for me. If you want us to analyze your effort then provide files. Follow instructions at bottom of my post.

    I have no idea if something might be different for Windows 7 64 bit Access 2010 64 bit.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #23
    ragsgold is offline Access & Excel Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2009
    Location
    Denver,CO
    Posts
    51
    Quote Originally Posted by June7 View Post
    The code works for me. If you want us to analyze your effort then provide files. Follow instructions at bottom of my post.

    I have no idea if something might be different for Windows 7 64 bit Access 2010 64 bit.
    I actually have Access 2007 and Windows XP SP2 at work. i guess its 32 bit. Will try and attach access and excel file per the instructuions

  9. #24
    ragsgold is offline Access & Excel Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2009
    Location
    Denver,CO
    Posts
    51
    Hi June 7,

    Attached are the files. Just rename the files by removing the "copy of" prefix.

    Some info about the files.

    MS Accsss - input File - linked excel file feeds to Access database

    Copy of Infinium Payroll Report1 - XLSM file that has a pivot & data table pulling data from the Access DB table - this is what needs to be refreshed.

    Copy of Infinium payroll Table Data - is Access 2007 DB

    Awaiting your analysis
    Attached Files Attached Files

  10. #25
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The Excel library was not selected in Access VBA. I reset the Access link to worksheet and also the workbook link to Access. Also created dummy records. The code runs without error but leaves an instance of Excel running in Windows Task Manager and data does not refresh. Manually running Refresh from ribbon or the macro does do the refresh. I added one line to the Access procedure and then it all worked:

    oExcel.ActiveWorkbook.Close (True)
    oExcel.Quit

    Why are you using Excel to report data instead of Access report object?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #26
    ragsgold is offline Access & Excel Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2009
    Location
    Denver,CO
    Posts
    51
    Quote Originally Posted by June7 View Post
    The Excel library was not selected in Access VBA. I reset the Access link to worksheet and also the workbook link to Access. Also created dummy records. The code runs without error but leaves an instance of Excel running in Windows Task Manager and data does not refresh. Manually running Refresh from ribbon or the macro does do the refresh. I added one line to the Access procedure and then it all worked:

    oExcel.ActiveWorkbook.Close (True)
    oExcel.Quit

    Why are you using Excel to report data instead of Access report object?
    Umm I see Microsoft Office 12.0 Access database Engine object Library "checked" and now checked the 12 excel Library. I included the code line you added. Now it runs without errors but its still not refreshing the excel. I get done pop message when i go to the excel its not refreshed.

    I use Excel because that report file will be emailed to a specific group of people who has a requirement to view it as pivot and data in two sheets. By Access report object you mean ? Access Reports? is it possible to do the same via access ?

  12. #27
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I will test again tonight but it was refreshing the Excel in my tests last night.

    Yes, I expect it could be replicated in Access. Probably need a subreport. If the people only need to view the data and not manipulate it, personally I would move mountain to eliminate the Excel component.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  13. #28
    ragsgold is offline Access & Excel Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2009
    Location
    Denver,CO
    Posts
    51
    Quote Originally Posted by June7 View Post
    I will test again tonight but it was refreshing the Excel in my tests last night.

    Yes, I expect it could be replicated in Access. Probably need a subreport. If the people only need to view the data and not manipulate it, personally I would move mountain to eliminate the Excel component.
    I just wanted to share this before you test

    My access code as below

    Public Function datexrefr()
    Dim oExcel As Excel.Application
    Set oExcel = CreateObject("Excel.Application")
    oExcel.Workbooks.Open ("Y:\Raghav\Access DB Projects\Infinium Actual payroll DB\Reports\Infinium Payroll Report1.xlsm")
    oExcel.Run "module4.myMacro"
    Do While Not oExcel.Worksheets("pivot").Range("D1") = "Done"
    DoEvents
    Loop
    oExcel.Worksheets("pivot").Range("D1") = "Start"
    oExcel.ActiveWorkbook.Close (True)
    oExcel.Quit
    End Function

  14. #29
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Does the Function work? Why make it a Function instead of Sub?

    I tested the file again and it works for me. I am at a loss as to what is going wrong for you.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  15. #30
    ragsgold is offline Access & Excel Developer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2009
    Location
    Denver,CO
    Posts
    51
    Quote Originally Posted by June7 View Post
    Does the Function work? Why make it a Function instead of Sub?

    I tested the file again and it works for me. I am at a loss as to what is going wrong for you.
    Code works without errors but, the problem is it doesnt refresh the excel file .

    in the mean time i figured out a traditional work around without codes. i created a macro with transfer spreadsheet and dumped data in sheet 2 and in sheet 1 i built a pivot based on sheet 2 in excel and set it to refresh on open.

    so macro runs dumps or over writes file and sheet and i created another line in the macro with Run app to open the excel that made the pivot to refresh. This is not 100% what i wanted but gets close to what i need. I have no clue why the code doesn't work for me

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 18
    Last Post: 09-04-2012, 12:06 PM
  2. Excel Import Macro Help in Access
    By vennies83 in forum Import/Export Data
    Replies: 5
    Last Post: 11-02-2011, 09:24 AM
  3. Running excel macro's from withing Access
    By zippy483 in forum Programming
    Replies: 5
    Last Post: 03-08-2011, 11:47 AM
  4. Replies: 1
    Last Post: 10-15-2010, 06:09 AM
  5. Running excel macro from access
    By timpepu in forum Programming
    Replies: 1
    Last Post: 02-26-2010, 11:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums