Neuigkeiten:

Wenn ihr euch für eine gute Antwort bedanken möchtet, im entsprechenden Posting einfach den Knopf "sag Danke" drücken!

Mobiles Hauptmenü

excel erstellen -> befüllen

Begonnen von Mik3, Februar 20, 2007, 08:44:16

⏪ vorheriges - nächstes ⏩

Mik3

Hi ihr :)

Wie kann ich aus Word heraus eine Excelldatei erstellen , und daten in diese Einfügen?

danke für eure Tips/Beispiele :)

Mike

Sebi

Hallo,

also Excel startest du per VBA

Private Sub CommandExcel()
Shell "excel.exe", vbNormalFocus
End Sub


lg Turbo
Liebe Grüße Sebi

Mik3


Mik3

hoi,

ich habe das auch mal mit nem Explorer gemacht..


Shell "explorer.exe", vbMaximizedFocus


will jetzt aber den Ordner , der Angezeigt wird auf C:\Programme\Test\  setzen, wie geht das denn?

thx, mike

atropos


Moin moin,

ganz einfach:

Shell "explorer.exe C:\Programme\Test\", vbMaximizedFocus
Gruss
atropos

Sebi

Hallo,

was magst du denn genau machen?

Willst du einen Dateiöffnen Dialog erzeugen?

Wenn ja geht das auch schöner.



lg Turbo
Liebe Grüße Sebi

imp666

#6
Du kannst Excel komplett automatisieren aus Access VBA heraus, hier nur mal ein Beispiel. Ich vermute das müsste auch in Word funktionieren....

   Dim objExcel As Object
   Dim objExcelWorkbook As Object
   Dim objExcelSheet As Object
   Dim strWorkspace As String
   Set objExcel = CreateObject("Excel.Application")
   strWorkspace = "c:\pfad\dateiname.xls"
   With objExcel
       .Visible = True
       .Interactive = True
       .Application.ScreenUpdating = False
       Set objExcelWorkbook = .Workbooks.Add
       Set objExcelSheet = objExcelWorkbook.sheets.Add
       objExcelSheet.Name = "Name des Excel-Sheets"
       objExcelSheet.Cells(1, 1).Value = "Irgendeine Überschrift"
       objExcelSheet.Range("A1:H1").MergeCells = True

       objExcelSheet.Cells(1, 1).interior.colorindex = 40
       objExcelSheet.Cells(1, 1).Font.Bold = True
       objExcelSheet.Cells(1, 1).Font.Name = "Arial"
       objExcelSheet.Cells(1, 1).Font.colorindex = 3
       objExcelSheet.Cells(1, 1).HorizontalAlignment = 3 ' entspr. "center"

       objExcelSheet.Cells(3, 1).Value = "Jahr"
       objExcelSheet.Cells(3, 2).Value = "Veranst.Nr."
       objExcelSheet.Range("A3:H3").interior.colorindex = 35
       objExcelSheet.Range("A3:H3").Font.Bold = True
       objExcelSheet.Cells.Columns(1).ColumnWidth = 7
       objExcelSheet.Cells.Columns(2).ColumnWidth = 10
       objExcelSheet.Range("A3:H3").borders(4).linestyle = 1 ' 1=solid / 2=dashed
       objExcelSheet.Range("A3:H3").borders(4).Width = 1
       objExcelSheet.Range("A3:H3").borders(4).colorindex = 1
       .Application.ScreenUpdating = True
   End With


Hondo

Hallo,
Excel-Automatisation ist der einzige richtige Weg, am besten noch per Late Binding, also ohne zusätzlichen Verweiss so wie von imp666 beschrieben.
Was aber noch fehlt ist eine Überprüfung ob es bereits eine existierende Excel-Instanz gibt. Dies macht man per API:


    Dim objExcel As Object
    Dim boolXL AS Boolean

    If fIsExcelRunning Then
        Set objExcel = GetObject(, "Excel.Application")
        boolXL = False
    Else
        Set objExcel = CreateObject("Excel.Application")
        boolXL = True
    End If

    With objXL
    ....
    End With

    If boolXL Then objExcel.Application.Quit



Dieser Code in ein Modul packen:

Private Const SW_SHOWNORMAL = 1

Private Declare Function apiFindWindow Lib "user32" Alias _
                                       "FindWindowA" (ByVal strClass As String, _
                                                      ByVal lpWindow As String) As Long

Private Declare Function apiSendMessage Lib "user32" Alias _
                                        "SendMessageA" (ByVal Hwnd As Long, ByVal Msg As Long, ByVal _
                                                                                               wParam As Long, lParam As Long) As Long

Private Declare Function apiSetForegroundWindow Lib "user32" Alias _
                                                "SetForegroundWindow" (ByVal Hwnd As Long) As Long

Private Declare Function apiShowWindow Lib "user32" Alias _
                                       "ShowWindow" (ByVal Hwnd As Long, ByVal nCmdShow As Long) As Long

Private Declare Function apiIsIconic Lib "user32" Alias _
                                     "IsIconic" (ByVal Hwnd As Long) As Long

Public Function fIsExcelRunning(Optional fActivate As Boolean) As Boolean
    Dim lngH As Long,  lngX As Long, lngTmp As Long
    Const WM_USER = 1024
    On Local Error GoTo fIsAppRunning_Err
    fIsAppRunning = False
    lngH = apiFindWindow("XLMain", vbNullString)
    If lngH <> 0 Then
        apiSendMessage lngH, WM_USER + 18, 0, 0
        lngX = apiIsIconic(lngH)
        If lngX <> 0 Then
            lngTmp = apiShowWindow(lngH, SW_SHOWNORMAL)
        End If
        If fActivate Then
            lngTmp = apiSetForegroundWindow(lngH)
        End If
        fIsAppRunning = True
    End If
fIsAppRunning_Exit:
    Exit Function
fIsAppRunning_Err:
    fIsAppRunning = False
    Resume fIsAppRunning_Exit
End Function


Was imp666 noch vergessen hat ist die Objekte zurückzusetzen am Schluss
set objExcel = Nothing
set ... usw.

Gruß Andreas

database

Hallo,

wobei dann die Frage noch aus dem Jahr 2007 stammt  ;)

Hondo

Äh, das ist jetzt aber peinlich.
Hab ich auch nicht drauf geachtet.
Aber vieleicht hilft es ja jemand anderem mit ähnlichem Problem.

Andreas

database

Hallo,

....es gibt Schlimmeres!  :D ;D ;)