Results 1 to 2 of 2
  1. #1
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544

    Question Excel code not working with Excel open

    I don't understand why this little bit of code is not working. If the user already has Excel open, it won't work. However, if Excel is not open code will work just fine. Thanks in advance!



    Code:
    Function funExpanCalendar(strFileLoc As String, strFileName As String, strFileExt As String)
        Dim strTableName As String
        Dim strVendor As String
        Dim xlApp As Object
        Dim xlSheet As Object
    '    Dim c As Range, lr As Long
        Dim ExcelRunning As Boolean
        
        ExcelRunning = IsExcelRunning()
        
        If ExcelRunning Then
            Set xlApp = GetObject(, "Excel.Application")
            gblExcelOpen = True
        Else
            Set xlApp = CreateObject("Excel.Application")
            gblExcelOpen = False
        End If
        
        xlApp.Application.DisplayAlerts = False
        
        Set xlSheet = xlApp.Workbooks.Open(strFileLoc & strFileName & strFileExt).Sheets(1)
    '    gblExcelOpen = True
        gblWrkBkOpen = True
    '=========================
        With xlApp.Application
            .Sheets.Add After:=Sheets(Sheets.Count)
            .Sheets(Sheets.Count).Select
            .Sheets(Sheets.Count).Name = "Data"
            .Sheets(1).Select
    '.....more code
        End With

  2. #2
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Solved....

    Code:
            .Sheets.Add After:=.Sheets(.Sheets.Count)
            .Sheets(.Sheets.Count).Select
            .Sheets(.Sheets.Count).Name = "Data"

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

Similar Threads

  1. Working with ADO Recordset & Excel
    By jgelpi16 in forum Programming
    Replies: 7
    Last Post: 03-15-2011, 01:58 PM
  2. Working with OLE excel charts in Access 2010
    By snoopy2003 in forum Programming
    Replies: 1
    Last Post: 02-23-2011, 12:46 PM
  3. Replies: 21
    Last Post: 02-14-2011, 02:51 PM
  4. VBA to open excel, import on close of excel
    By bdaniel in forum Programming
    Replies: 0
    Last Post: 03-20-2010, 02:45 PM
  5. Excel number format not working in Access
    By toad848 in forum Access
    Replies: 3
    Last Post: 03-24-2009, 11:06 AM

Tags for this Thread

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