Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Tabelle in Word ansprechen

Empfohlene Antworten

Veröffentlicht

Hallo!

Über folgenden Code öffne ich ein Word-Template:

Dim oWord As Object

Dim doc As Object

oWord = CreateObject("Word.Application")

doc = oWord.Documents.Add(Template:="C:/Template/Template.dot")

Wie kann ich denn nun eine Tabelle ansprechen?

Wenn ich hinter einem Punkt (z.B. hinter oWord.Documents) strg+space drücke, bekomme ich keine Auswahl. Warum?

Danke!!

ich geb dir mal meinen gesamten code, so wies ich mal gemacht hab (vb.net):

    Private Sub vWord()


        Dim oWord As New Word.Application

        Dim oDoc As New Word.Document

        Dim oTable As Word.Table

        Dim oPara1 As Word.Paragraph

        Dim sFileName As String

        Dim sSql As String

        Dim oRs As New ADODB.Recordset

        Dim i As Long

        Dim sVersion As String


        Try


            sFileName = oStdFct.vOpenDialog(OpenFileDialog1)


            oDoc = oWord.Documents.Open(FileName:=sFileName)


            sSql = " *** sql select *** "


            i = 2


            oRs.Open(sSql, oConn)

            sVersion = oRs(1).Value

            While Not oRs.EOF

                oDoc.Tables.Item(1).Rows.Add(oDoc.Tables.Item(1).Rows.Item(2))

                If oRs(1).Value <> sVersion Then

                    oDoc.Tables.Item(1).Cell(2, 1).Range.Text = oRs(1).Value & vbNewLine & Format(Date.Now, "dd.MM.yyyy")

                    sVersion = oRs(1).Value

                Else

                    If i = 2 Then

                        oDoc.Tables.Item(1).Cell(2, 1).Range.Text = oRs(1).Value & vbNewLine & Format(Date.Now, "dd.MM.yyyy")

                    Else

                        oDoc.Tables.Item(1).Cell(2, 1).Range.Text = oRs(1).Value

                    End If

                End If

                oDoc.Tables.Item(1).Cell(2, 2).Range.Text = oRs(0).Value

                oDoc.Tables.Item(1).Cell(2, 3).Range.Text = oRs(2).Value

                i = i + 1

                oRs.MoveNext()

            End While

            oRs.Close()

            Dim a, b, c As Object

            oWord.Documents.Save(a, 

            oWord.Documents.Close(a, b, c)


        Catch ex As Exception

            MsgBox(Err.Description & vbNewLine & _

            "Entweder ist das Worddokument bereits offen oder wurde nicht korrekt geschlossen.", MsgBoxStyle.Critical)

            Exit Function

        End Try

    End Function[/code]

Hi,

Wenn ich hinter einem Punkt (z.B. hinter oWord.Documents) strg+space drücke, bekomme ich keine Auswahl. Warum

das kommt daher, dass Du die Word - Lib nicht eingebunden hast:

Menü->Projekt->Verweise->Microsoft Word XX Lib : Haken setzen.

Ansonsten schau Dir mal dies an, sehr informativ:

http://www.activevb.de/rubriken/faq/faq0015.html

ich geb dir mal meinen gesamten code, so wies ich mal gemacht hab (vb.net):

    Private Sub vWord()


        Dim oWord As New Word.Application

        Dim oDoc As New Word.Document

        Dim oTable As Word.Table

        Dim oPara1 As Word.Paragraph

        Dim sFileName As String

        Dim sSql As String

        Dim oRs As New ADODB.Recordset

        Dim i As Long

        Dim sVersion As String


        Try


            sFileName = oStdFct.vOpenDialog(OpenFileDialog1)


            oDoc = oWord.Documents.Open(FileName:=sFileName)


            sSql = " *** sql select *** "


            i = 2


            oRs.Open(sSql, oConn)

            sVersion = oRs(1).Value

            While Not oRs.EOF

                oDoc.Tables.Item(1).Rows.Add(oDoc.Tables.Item(1).Rows.Item(2))

                If oRs(1).Value <> sVersion Then

                    oDoc.Tables.Item(1).Cell(2, 1).Range.Text = oRs(1).Value & vbNewLine & Format(Date.Now, "dd.MM.yyyy")

                    sVersion = oRs(1).Value

                Else

                    If i = 2 Then

                        oDoc.Tables.Item(1).Cell(2, 1).Range.Text = oRs(1).Value & vbNewLine & Format(Date.Now, "dd.MM.yyyy")

                    Else

                        oDoc.Tables.Item(1).Cell(2, 1).Range.Text = oRs(1).Value

                    End If

                End If

                oDoc.Tables.Item(1).Cell(2, 2).Range.Text = oRs(0).Value

                oDoc.Tables.Item(1).Cell(2, 3).Range.Text = oRs(2).Value

                i = i + 1

                oRs.MoveNext()

            End While

            oRs.Close()

            Dim a, b, c As Object

            oWord.Documents.Save(a, 

            oWord.Documents.Close(a, b, c)


        Catch ex As Exception

            MsgBox(Err.Description & vbNewLine & _

            "Entweder ist das Worddokument bereits offen oder wurde nicht korrekt geschlossen.", MsgBoxStyle.Critical)

            Exit Function

        End Try

    End Function[/code]

Ich würde, wenn ich schon .NET mache, auch ADO.NET verwenden und nicht ADODB, da fallen doch die schönen neuen Techniken unter den Tisch...

hö?

welche neuen techniken?

das war mein erstes programm mit vb.net

bin da noch nicht so fit...

was für vorteile hat das?

ich mein, für mich reicht adodb hier auch...

Hi,

sicher kann ADO reichen (in manchen Fällen reicht auch DAO anstatt ADO), doch hat ADO.NET ein neues Konzept und ist zukunftsicherer.

Hier ein Artikel ("Was ist neu in ADO.NET?")

http://www.aspheute.com/artikel/20001031.htm

sondern bietet ernstzunehmende Vorteile in der Programmierung, Wartung, Performance und dem Datenaustausch zwischen einzelnen Komponenten, der auf dem universellen XML Standard basiert

Wesentlicher Vorteil ist, dass ADO.NET verbindungslos arbeitet, d.h. die Daten werden im lokalen Speicher des Anwenders gehalten und man hat nicht ständig irgnedwelche Connections offen.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.