Results 1 to 9 of 9
  1. #1
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919

    Create Excel workbook from code

    The code below runs successfully in both 2003 and 2010 environments. However, in the 2010 (Win 7 Pro) environment, it's necessary to open the xls file with Excel 2010 and then save it in the Excel 97-2003 format before it's accepted as an xls file in other applications, like an upload to a telephone calling service. What changes, if there are any, that can be included/added to my code that will get the xls file in the proper format when created from within the 2010 environment. As it is now, the fronend mde file is created in the 2003 environment.

    Thanks,
    Bill

    Private Sub OutputToExcel()
    Dim oExcel As Object
    Dim oBook As Object
    Dim oSheet As Object



    'Start a new workbook in Excel
    Set oExcel = CreateObject("Excel.Application")
    Set oBook = oExcel.Workbooks.Add

    Set oSheet = oBook.Worksheets(1)

    'Transfer the array to the worksheet starting at cell A1 (Column headings already in 1st row of strBCarray)
    oSheet.Range("A1").Resize(iRow, jCol).Value = strBCarray

    'Save the Workbook and Quit Excel
    Kill (XLSName)
    oBook.SaveAs XLSName
    oExcel.Quit
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Variables XLSName, iRow, JCol, strBCarry are not declared nor set. Their values are 0 or empty. Is that what you want?

    Review: http://blogs.office.com/b/microsoft-...xcel-2007.aspx

    Try:
    oBook.SaveAs XLSName, 56
    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. #3
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    The variables you mention are global to the module:


    Option Compare Database
    Option Base 1
    Option Explicit
    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*=*=*=*
    ' The purpose of this module is to establish an Excel file containing the groups and their members who are
    ' to receive automated telephone messages.

    (snip)

    '*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=* =*=*=*=*

    Dim strGrpIDs() As String 'The corresponding group names are loaded into the array strColHdgs.
    Dim iGroups As Integer 'Count of the number of groups found when Group information loaded.

    Dim strColHdgs() As String
    Dim strBCarray() As String 'This array will contain the rows and columns from which we'll load the cells in the XLS file
    Dim iRow As Integer 'Row index for the BCarray
    Dim jCol As Integer 'Column index for the BCarray
    Dim XLSName As String 'Name of the Excel file.
    Dim grpTxtFile As String
    Dim strTxtEditor As String


    I will add the ", 56" and post back.

  4. #4
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    The use of the added ", 56" is not a supported method in Access 2003.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Rats! That worked so nicely in Access2007. Sorry, I no longer have Access2003 available. You might be stuck with your original process.
    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.

  6. #6
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    It might require the 2010 object library. When the 2010 environment becomes available, I'll compile the app and see if I get different results.
    Thanks for your thoughts.
    Bill

  7. #7
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    Hello June7,
    What does the parameter "56" signify to the oBook.SaveAs command?
    Bill

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    I only know what I read in the link I referenced: file format
    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.

  9. #9
    GraeagleBill's Avatar
    GraeagleBill is offline Experienced Old Geezer
    Windows 7 64bit Access 2003
    Join Date
    Feb 2011
    Posts
    1,919
    Got it!

    Thanks,
    Bill

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Send an excel workbook from access
    By haazzaa in forum Access
    Replies: 1
    Last Post: 07-26-2012, 05:40 PM
  2. Replies: 1
    Last Post: 04-30-2012, 05:10 PM
  3. Link to Excel Workbook
    By Shelly9633 in forum Access
    Replies: 2
    Last Post: 01-06-2012, 10:43 AM
  4. Linking Workbook and Overwriting Excel File
    By Atheron in forum Import/Export Data
    Replies: 2
    Last Post: 10-08-2011, 03:44 PM
  5. Deleting Worksheets on a Excel workbook
    By BED in forum Programming
    Replies: 0
    Last Post: 07-27-2010, 01:20 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