27 | 06 | 2017

Connect to Excel

'-----------------------------------------------------------------------------
Sub Connect2Excel()
'-----------------------------------------------------------------------------

'****************************************
'*** Code from VisibleVisual.com ********
'****************************************


Dim eXls As Excel.Application
Dim eXlsWorkbook As Excel.Workbooks
Dim eXlsSheet As Excel.Worksheet

On Error Resume Next

    'Excel MUST be running for this sample
    Set XLS = GetObject(, "Excel.Application")
    
    'Check to see if Excel is running
    
    If Err Then
        'Excel is not active
        Err.Clear
        Set eXls = CreateObject("Excel.Application")
        'Check if Excel Started
        If Err Then
        'Excel failed to start check all values or check if Excel is installed.
        Exit Sub
        End If
    End If

eXls.Visible = True

'Excel is now running dd a workbook
Set eXlsWorkbook = XLS.Workbooks.Add

'Add a worksheet
Set eXlsSheet = XLS.Worksheets.Add

'Now you can add text just by using the cells coordinates
eXlsSheet.Cells(1, 1).Value = "Hello World CELL A1"

'Instead of the Cell coordinates u can use the cell name
eXlsSheet.Range("A2").Value = "Hello World CELL A2"

End Sub
Login

Sign up now and upload your code to the website.

Help us to continue.....
Statistics
Articles View Hits
2288511
Latest Articles