Word Daten auslesen und an Excel übergeben, ausführen vor Speichervorgang.

  • Word

Es gibt 7 Antworten in diesem Thema. Der letzte Beitrag () ist von petaod.

    Word Daten auslesen und an Excel übergeben, ausführen vor Speichervorgang.

    Guten Tag liebe VB Community.
    Ich bin neu in diesem Forum und auch was die VB(A) programmierung angeht noch sehr laienhaft.
    Ich hoffe das mir hier geholfen werden kann. Das würde mich außerordentlich freuen.

    Zu meinem Problem.

    Ich habe ein Formular in MS Word erstellt mit Pflichtfeldern, DropDown Menüs usw.
    Wie bereits erwähnt habe ich mit Hilfe von VBA einige dieser Formularfelder zu Pflichtfeldern gemacht.
    Vor jedem Speichervorgang prüft das Script ob alle notwendigen Felder ausgefüllt sind und beanstandet dieses falls nötig.

    Nun sollen einige dieser Felder ausgelesen werden und deren Inhalt soll an eine Excel Tabelle übergeben werden.
    Den dafür nötigen Code habe ich ebenfalls bereits erstellt und er funktioniert auch soweit.
    Jedoch habe ich ein paar Probleme mit denen ich etwas Hilfe gebrauchen könnte.

    1.
    Wenn Word die Daten an Excel übergibt, dann schreibt Excel diese immer in die selbe Zeile obwohl ich meiner Meinung nach deklariert habe dafür immer eine neue Zeile zu verwenden.

    Frage:

    Gibt es eine Möglichkeit Excel zu sagen, Prüfe Zeile XY wenn Zeile XY bereits belegt, dann gehe eine Zeile darunter und trage dort die Daten ein. Zeile ebenfalls belegt? Dann gehe eine Zeile weiter bis du eine leere Zeile findest.

    2.
    Ich hätte ganz gerne vermieden, da dieses Formular von Leuten ausgefüllt wird die so rein gar keine Ahnung von VBA und dem Editor haben, das diese das Script von Hand ausführen müssen.

    Frage:

    Wie stelle ich es an, das Word diesen Teil Des Scripts ebenfalls vor einem Speichervorgang ausführt, allerdings nachdem die Pflichtfelder das Script auf völlständigkeit geprüft haben jedoch vor dem eigentlich Speichervorgang. Ich hoffe ich habe das verständlich genug beschrieben.

    Das war erstmal alles.


    Hier ist der Code für das Script.
    Dieser Teil befindet sich direkt in ThisDocument:

    Quellcode

    1. Private Sub Document_Open()
    2. End Sub
    3. Sub FilePrintDefault()
    4. If Checkfields = True Then ActiveDocument.PrintOut
    5. End Sub
    6. Sub FilePrint()
    7. FilePrintDefault
    8. End Sub
    9. Sub FileSave()
    10. If Checkfields = True Then
    11. If ActiveDocument.Path = "" Then
    12. FileSaveAs
    13. End If
    14. ActiveDocument.Save
    15. End If
    16. End Sub
    17. Sub FileSaveAs()
    18. If Checkfields = True Then
    19. Dialogs(wdDialogFileSaveAs).Show
    20. End If
    21. End Sub
    22. Private Sub ComboBox1_DropDownClick()
    23. ComboBox1.List = Array(" ", "Armatur funktionssicher instandgesetzt.", "Weitere Maßnahmen erforderlich. (siehe Text)", "Wartung nicht möglich. (siehe Text)")
    24. End Sub
    25. Private Sub ComboBox1_Change()
    26. If ComboBox1.Text = " " Then
    27. ComboBox1.BackColor = RGB(224, 224, 224)
    28. ActiveDocument.FormFields("Hinweise").Result = ""
    29. O4A.Enabled = True
    30. O4B.Enabled = True
    31. End If
    32. If ComboBox1.Text = "Armatur funktionssicher instandgesetzt." Then
    33. ComboBox1.BackColor = RGB(34, 139, 34)
    34. O4A.Enabled = True
    35. O4B.Enabled = True
    36. End If
    37. If ComboBox1.Text = "Weitere Maßnahmen erforderlich. (siehe Text)" Then
    38. ComboBox1.BackColor = RGB(255, 255, 0)
    39. End If
    40. If ComboBox1.Text = "Wartung nicht möglich. (siehe Text)" Then
    41. ComboBox1.BackColor = RGB(255, 0, 0)
    42. End If
    43. End Sub
    44. Private Function Checkfields() As Boolean
    45. If ActiveDocument.FormFields("Hersteller").Result = " " Then
    46. MsgBox "Bitte Hersteller auswählen!"
    47. Checkfields = False
    48. ActiveDocument.FormFields("Hersteller").Select
    49. Exit Function
    50. End If
    51. If ActiveDocument.FormFields("EquiNr").Result = "" Then
    52. MsgBox "Bitte Equipment-Nr. eintragen!"
    53. Checkfields = False
    54. ActiveDocument.FormFields("EquiNr").Select
    55. Exit Function
    56. End If
    57. If ActiveDocument.FormFields("Typ").Result = "" Then
    58. MsgBox "Bitte Typ eintragen!"
    59. Checkfields = False
    60. ActiveDocument.FormFields("Hinweise").Result = ""
    61. ActiveDocument.FormFields("Typ").Select
    62. Exit Function
    63. End If
    64. If ActiveDocument.FormFields("Typ").Result = "EH/Z" Then
    65. MsgBox "ACHTUNG!" & vbCrLf & "" & vbCrLf & "Zulassung zurückgezogen!" & vbCrLf & _
    66. "System wird auf 'Rot' gesetzt."
    67. Checkfields = False
    68. ComboBox1 = "Weitere Maßnahmen erforderlich. (siehe Text)"
    69. ComboBox1.BackColor = RGB(255, 0, 0)
    70. ActiveDocument.FormFields("Hinweise").Result = _
    71. "Für dieses System wurde 1989 die Zulassung zurückgezogen. Wir empfehlen ausdrücklich den Austausch gegen ein System nach dem aktuellen Stand der Technik - ATEX (EN 12874/ISO 16852)."
    72. Exit Function
    73. End If
    74. If ActiveDocument.FormFields("Typ").Result = "EH/K" Then
    75. MsgBox "ACHTUNG!" & vbCrLf & "" & vbCrLf & "Zulassung zurückgezogen!" & vbCrLf & _
    76. "System wird auf 'Rot' gesetzt."
    77. Checkfields = False
    78. ComboBox1 = "Weitere Maßnahmen erforderlich. (siehe Text)"
    79. ComboBox1.BackColor = RGB(255, 0, 0)
    80. ActiveDocument.FormFields("Hinweise").Result = _
    81. "Für dieses System wurde 1989 die Zulassung zurückgezogen. Wir empfehlen ausdrücklich den Austausch gegen ein System nach dem aktuellen Stand der Technik - ATEX (EN 12874/ISO 16852)."
    82. Exit Function
    83. End If
    84. If ActiveDocument.FormFields("Typ").Result = "SD/BK" Then
    85. MsgBox "ACHTUNG!" & vbCrLf & "" & vbCrLf & "Zulassung zurückgezogen!" & vbCrLf & _
    86. "System wird auf 'Rot' gesetzt."
    87. Checkfields = False
    88. ComboBox1 = "Weitere Maßnahmen erforderlich. (siehe Text)"
    89. ComboBox1.BackColor = RGB(255, 0, 0)
    90. ActiveDocument.FormFields("Hinweise").Result = _
    91. "Für dieses System wurde 1989 die Zulassung zurückgezogen. Wir empfehlen ausdrücklich den Austausch gegen ein System nach dem aktuellen Stand der Technik - ATEX (EN 12874/ISO 16852)."
    92. Exit Function
    93. End If
    94. If ActiveDocument.FormFields("Typ").Result = "VD/BK" Then
    95. MsgBox "ACHTUNG!" & vbCrLf & "" & vbCrLf & "Zulassung zurückgezogen!" & vbCrLf & _
    96. "System wird auf 'Rot' gesetzt."
    97. Checkfields = False
    98. ComboBox1 = "Weitere Maßnahmen erforderlich. (siehe Text)"
    99. ComboBox1.BackColor = RGB(255, 0, 0)
    100. ActiveDocument.FormFields("Hinweise").Result = _
    101. "Für dieses System wurde 1989 die Zulassung zurückgezogen. Wir empfehlen ausdrücklich den Austausch gegen ein System nach dem aktuellen Stand der Technik - ATEX (EN 12874/ISO 16852)."
    102. Exit Function
    103. End If
    104. If ActiveDocument.FormFields("Typ").Result = "UB/LH" Then
    105. MsgBox "ACHTUNG!" & vbCrLf & "" & vbCrLf & "Zulassung eingeschränkt!" & vbCrLf & _
    106. "System bleibt auf 'Grün', sofern keine Mängel vorhanden."
    107. Checkfields = False
    108. ComboBox1 = "Weitere Maßnahmen erforderlich. (siehe Text)"
    109. ComboBox1.BackColor = RGB(34, 139, 34)
    110. ActiveDocument.FormFields("Hinweise").Result = _
    111. "Die betroffenen Altarmaturen entsprechen seit 1989 nicht mehr dem Stand der Technik. Wir empfehlen ausdrücklich den Austausch!"
    112. Exit Function
    113. End If
    114. If ActiveDocument.FormFields("Typ").Result = "UB/D" Then
    115. MsgBox "ACHTUNG!" & vbCrLf & "" & vbCrLf & "Zulassung eingeschränkt!" & vbCrLf & _
    116. "System bleibt auf 'Grün', sofern keine Mängel vorhanden."
    117. Checkfields = False
    118. ComboBox1 = "Weitere Maßnahmen erforderlich. (siehe Text)"
    119. ComboBox1.BackColor = RGB(34, 139, 34)
    120. ActiveDocument.FormFields("Hinweise").Result = _
    121. "Die betroffenen Altarmaturen entsprechen seit 1989 nicht mehr dem Stand der Technik. Wir empfehlen ausdrücklich den Austausch!"
    122. Exit Function
    123. End If
    124. If ActiveDocument.FormFields("Typ").Result = "UB/DV" Then
    125. MsgBox "ACHTUNG!" & vbCrLf & "" & vbCrLf & "Zulassung eingeschränkt!" & vbCrLf & _
    126. "System bleibt auf 'Grün', sofern keine Mängel vorhanden."
    127. Checkfields = False
    128. ComboBox1 = "Weitere Maßnahmen erforderlich. (siehe Text)"
    129. ComboBox1.BackColor = RGB(34, 139, 34)
    130. ActiveDocument.FormFields("Hinweise").Result = _
    131. "Die betroffenen Altarmaturen entsprechen seit 1989 nicht mehr dem Stand der Technik. Wir empfehlen ausdrücklich den Austausch!"
    132. Exit Function
    133. End If
    134. If ActiveDocument.FormFields("NW").Result = "" Then
    135. MsgBox "Bitte Nennweite eintragen!"
    136. Checkfields = False
    137. ActiveDocument.FormFields("NW").Select
    138. Exit Function
    139. End If
    140. If ActiveDocument.FormFields("PTB").Result = "" Then
    141. MsgBox "Bitte PTB/ATEX Nr. eintragen!"
    142. Checkfields = False
    143. ActiveDocument.FormFields("PTB").Select
    144. Exit Function
    145. End If
    146. If ActiveDocument.FormFields("SNR").Result = "" Then
    147. MsgBox "Bitte Seriennummer eintragen!"
    148. Checkfields = False
    149. ActiveDocument.FormFields("SNR").Select
    150. Exit Function
    151. End If
    152. If ActiveDocument.FormFields("GWRKST").Result = " " Then
    153. MsgBox "Bitte Gehäusewerkstoff auswählen!"
    154. Checkfields = False
    155. ActiveDocument.FormFields("GWRKST").Select
    156. Exit Function
    157. End If
    158. If ActiveDocument.FormFields("GDTNG").Result = " " Then
    159. MsgBox "Bitte Gehäusedichtung auswählen!"
    160. Checkfields = False
    161. ActiveDocument.FormFields("GDTNG").Select
    162. Exit Function
    163. End If
    164. If ActiveDocument.FormFields("MWRKST").Result = " " Then
    165. MsgBox "Bitte Membranwerkstoff auswählen!"
    166. Checkfields = False
    167. ActiveDocument.FormFields("MWRKST").Select
    168. Exit Function
    169. End If
    170. If ActiveDocument.FormFields("MED").Result = " " Then
    171. MsgBox "Bitte Belastungsmedium auswählen!"
    172. Checkfields = False
    173. ActiveDocument.FormFields("MED").Select
    174. Exit Function
    175. End If
    176. If ActiveDocument.FormFields("PMBAR").Result = "" Then
    177. MsgBox "Bitte Einstellüberdruck eintragen!"
    178. Checkfields = False
    179. ActiveDocument.FormFields("PMBAR").Select
    180. Exit Function
    181. End If
    182. If ActiveDocument.FormFields("PVWRKST").Result = " " Then
    183. MsgBox "Bitte Überdruck Ventilteller-Werkstoff auswählen!"
    184. Checkfields = False
    185. ActiveDocument.FormFields("PVWRKST").Select
    186. Exit Function
    187. End If
    188. If ActiveDocument.FormFields("PVDTNG").Result = " " Then
    189. MsgBox "Bitte Überdruck Ventilteller-Dichtung auswählen!"
    190. Checkfields = False
    191. ActiveDocument.FormFields("PVDTNG").Select
    192. Exit Function
    193. End If
    194. If ActiveDocument.FormFields("VMBAR").Result = "" Then
    195. MsgBox "Bitte Einstellunterdruck eintragen!"
    196. Checkfields = False
    197. ActiveDocument.FormFields("VMBAR").Select
    198. Exit Function
    199. End If
    200. If ActiveDocument.FormFields("VVWRKST").Result = " " Then
    201. MsgBox "Bitte Unterdruck Ventilteller-Werkstoff auswählen!"
    202. Checkfields = False
    203. ActiveDocument.FormFields("VVWRKST").Select
    204. Exit Function
    205. End If
    206. If ActiveDocument.FormFields("VVDTNG").Result = " " Then
    207. MsgBox "Bitte Unterdruck Ventilteller-Dichtung auswählen!"
    208. Checkfields = False
    209. ActiveDocument.FormFields("VMBAR").Select
    210. Exit Function
    211. End If
    212. If ActiveDocument.FormFields("FFA").Enabled = True And ActiveDocument.FormFields("FFA").Result = "" Then
    213. MsgBox "Bitte die Anzahl Filterscheiben eintragen!"
    214. Checkfields = False
    215. ActiveDocument.FormFields("FFA").Select
    216. Exit Function
    217. End If
    218. If ActiveDocument.FormFields("SW").Enabled = True And ActiveDocument.FormFields("SW").Result = "" Then
    219. MsgBox "Bitte die Spaltweite eintragen!"
    220. Checkfields = False
    221. ActiveDocument.FormFields("SW").Select
    222. Exit Function
    223. End If
    224. If ActiveDocument.FormFields("WR").Enabled = True And ActiveDocument.FormFields("WR").Result = " " Then
    225. MsgBox "Bitte die Wickelrichtung auswählen!"
    226. Checkfields = False
    227. ActiveDocument.FormFields("WR").Select
    228. Exit Function
    229. End If
    230. If ActiveDocument.FormFields("FFWRKST").Enabled = True And ActiveDocument.FormFields("FFWRKST").Result = " " Then
    231. MsgBox "Bitte den Flammenfilter-Werkstoff auswählen!"
    232. Checkfields = False
    233. ActiveDocument.FormFields("FFWRKST").Select
    234. Exit Function
    235. End If
    236. If ActiveDocument.FormFields("FKWRKST").Enabled = True And ActiveDocument.FormFields("FKWRKST").Result = " " Then
    237. MsgBox "Bitte den Filterkäfig-Werkstoff auswählen!"
    238. Checkfields = False
    239. ActiveDocument.FormFields("FKWRKST").Select
    240. Exit Function
    241. End If
    242. If ActiveDocument.FormFields("ZWL").Enabled = True And ActiveDocument.FormFields("ZWL").Result = "" Then
    243. MsgBox "Bitte die Anzahl der Zwischenlagen eintragen!"
    244. Checkfields = False
    245. ActiveDocument.FormFields("ZWL").Select
    246. Exit Function
    247. End If
    248. If ActiveDocument.FormFields("PEPP").Enabled = True And ActiveDocument.FormFields("PEPP").Result = "" Then
    249. MsgBox "Bitte die Überdruck mbar eintragen!"
    250. Checkfields = False
    251. ActiveDocument.FormFields("PEPP").Select
    252. Exit Function
    253. End If
    254. If ActiveDocument.FormFields("PEPT").Enabled = True And ActiveDocument.FormFields("PEPT").Result = "" Then
    255. MsgBox "Bitte die Überdruck Prüfdauer eintragen!"
    256. Checkfields = False
    257. ActiveDocument.FormFields("PEPT").Select
    258. Exit Function
    259. End If
    260. If ActiveDocument.FormFields("PEPZ").Enabled = True And ActiveDocument.FormFields("PEPZ").Result = "" Then
    261. MsgBox "Bitte die Überdruck Prüfzyklen eintragen!"
    262. Checkfields = False
    263. ActiveDocument.FormFields("PEPZ").Select
    264. Exit Function
    265. End If
    266. If ActiveDocument.FormFields("PEVP").Enabled = True And ActiveDocument.FormFields("PEVP").Result = "" Then
    267. MsgBox "Bitte die Unterdruck mbar eintragen!"
    268. Checkfields = False
    269. ActiveDocument.FormFields("PEVP").Select
    270. Exit Function
    271. End If
    272. If ActiveDocument.FormFields("PEVT").Enabled = True And ActiveDocument.FormFields("PEVT").Result = "" Then
    273. MsgBox "Bitte die Unterdruck Prüfdauer eintragen!"
    274. Checkfields = False
    275. ActiveDocument.FormFields("PEVT").Select
    276. Exit Function
    277. End If
    278. If ActiveDocument.FormFields("PEVZ").Enabled = True And ActiveDocument.FormFields("PEVZ").Result = "" Then
    279. MsgBox "Bitte die Unterdruck Prüfzyklen eintragen!"
    280. Checkfields = False
    281. ActiveDocument.FormFields("PEVZ").Select
    282. Exit Function
    283. End If
    284. If ActiveDocument.FormFields("PEN").Enabled = True And ActiveDocument.FormFields("PEN").Result = "" Then
    285. MsgBox "Bitte Name des Prüfers eintragen!"
    286. Checkfields = False
    287. ActiveDocument.FormFields("PEN").Select
    288. Exit Function
    289. End If
    290. If ActiveDocument.FormFields("PPPP").Enabled = True And ActiveDocument.FormFields("PPPP").Result = "" Then
    291. MsgBox "Bitte die Überdruck mbar eintragen!"
    292. Checkfields = False
    293. ActiveDocument.FormFields("PPPP").Select
    294. Exit Function
    295. End If
    296. If ActiveDocument.FormFields("PPPT").Enabled = True And ActiveDocument.FormFields("PPPT").Result = "" Then
    297. MsgBox "Bitte die Überdruck Prüfdauer eintragen!"
    298. Checkfields = False
    299. ActiveDocument.FormFields("PPPT").Select
    300. Exit Function
    301. End If
    302. If ActiveDocument.FormFields("PPPZ").Enabled = True And ActiveDocument.FormFields("PPPZ").Result = "" Then
    303. MsgBox "Bitte die Überdruck Prüfzyklen eintragen!"
    304. Checkfields = False
    305. ActiveDocument.FormFields("PPPZ").Select
    306. Exit Function
    307. End If
    308. If ActiveDocument.FormFields("PPVP").Enabled = True And ActiveDocument.FormFields("PPVP").Result = "" Then
    309. MsgBox "Bitte die Unterdruck mbar eintragen!"
    310. Checkfields = False
    311. ActiveDocument.FormFields("PPVP").Select
    312. Exit Function
    313. End If
    314. If ActiveDocument.FormFields("PPVT").Enabled = True And ActiveDocument.FormFields("PPVT").Result = "" Then
    315. MsgBox "Bitte die Unterdruck Prüfdauer eintragen!"
    316. Checkfields = False
    317. ActiveDocument.FormFields("PPVT").Select
    318. Exit Function
    319. End If
    320. If ActiveDocument.FormFields("PPVZ").Enabled = True And ActiveDocument.FormFields("PPVZ").Result = "" Then
    321. MsgBox "Bitte die Unterdruck Prüfzyklen eintragen!"
    322. Checkfields = False
    323. ActiveDocument.FormFields("PPVZ").Select
    324. Exit Function
    325. End If
    326. If ActiveDocument.FormFields("PPN").Enabled = True And ActiveDocument.FormFields("PPN").Result = "" Then
    327. MsgBox "Bitte Name des Prüfers eintragen!"
    328. Checkfields = False
    329. ActiveDocument.FormFields("PPN").Select
    330. Exit Function
    331. End If
    332. If ComboBox1.Text = " " Then
    333. MsgBox "Bitte Gerätestatus auswählen!"
    334. Checkfields = False
    335. ComboBox1.Select
    336. Exit Function
    337. End If
    338. If ComboBox2.Text = " " Then
    339. MsgBox "Bitte Wartungszyklus auswählen!"
    340. Checkfields = False
    341. ComboBox2.Select
    342. Exit Function
    343. End If
    344. If ActiveDocument.FormFields("Ort").Result = "" Then
    345. MsgBox "Bitte Ort eintragen!"
    346. Checkfields = False
    347. ActiveDocument.FormFields("Ort").Select
    348. Exit Function
    349. End If
    350. If ActiveDocument.FormFields("Aussteller").Result = "" Then
    351. MsgBox "Bitte Aussteller eintragen!"
    352. Checkfields = False
    353. ActiveDocument.FormFields("Aussteller").Select
    354. Exit Function
    355. End If
    356. Checkfields = True
    357. End Function
    358. Private Sub A1_Click()
    359. If A1.Value = True Then
    360. A2.Value = False
    361. End If
    362. End Sub
    363. Private Sub A2_Click()
    364. If A2.Value = True Then
    365. A1.Value = False
    366. End If
    367. End Sub
    368. Private Sub ColorBarAX11_GotFocus()
    369. End Sub
    370. Private Sub armaturBild_Click()
    371. If ActiveDocument.ProtectionType <> wdNoProtection Then
    372. ActiveDocument.Unprotect Password:=""
    373. ActiveDocument.ToggleFormsDesign
    374. End If
    375. End Sub
    376. Private Sub ComboBox2_DropButtonClick()
    377. ComboBox2.List = Array(" ", "1 Monat", "2 Monate", "3 Monate", "6 Monate", "12 Monate")
    378. End Sub
    379. Private Sub Image1_Click()
    380. End Sub
    381. Private Sub O1A_Click()
    382. If O1A.Value = True Then
    383. O1B.Value = False
    384. End If
    385. End Sub
    386. Private Sub O1B_Click()
    387. If O1B.Value = True Then
    388. O1A.Value = False
    389. End If
    390. End Sub
    391. Private Sub O2A_Click()
    392. If O2A.Value = True Then
    393. O2B.Value = False
    394. O2C.Value = False
    395. ActiveDocument.FormFields("PEPP").Enabled = True
    396. ActiveDocument.FormFields("PEPT").Enabled = True
    397. ActiveDocument.FormFields("PEPZ").Enabled = True
    398. ActiveDocument.FormFields("PEVP").Enabled = True
    399. ActiveDocument.FormFields("PEVT").Enabled = True
    400. ActiveDocument.FormFields("PEVZ").Enabled = True
    401. ActiveDocument.FormFields("PEN").Enabled = True
    402. ActiveDocument.FormFields("PPPP").Enabled = False
    403. ActiveDocument.FormFields("PPPT").Enabled = False
    404. ActiveDocument.FormFields("PPPZ").Enabled = False
    405. ActiveDocument.FormFields("PPVP").Enabled = False
    406. ActiveDocument.FormFields("PPVT").Enabled = False
    407. ActiveDocument.FormFields("PPVZ").Enabled = False
    408. ActiveDocument.FormFields("PPN").Enabled = False
    409. ActiveDocument.FormFields("PPPP").Result = ""
    410. ActiveDocument.FormFields("PPPT").Result = ""
    411. ActiveDocument.FormFields("PPPZ").Result = ""
    412. ActiveDocument.FormFields("PPVP").Result = ""
    413. ActiveDocument.FormFields("PPVT").Result = ""
    414. ActiveDocument.FormFields("PPVZ").Result = ""
    415. ActiveDocument.FormFields("PPN").Result = ""
    416. End If
    417. End Sub
    418. Private Sub O2B_Click()
    419. If O2B.Value = True Then
    420. O2A.Value = False
    421. O2C.Value = False
    422. ActiveDocument.FormFields("PEPP").Enabled = False
    423. ActiveDocument.FormFields("PEPT").Enabled = False
    424. ActiveDocument.FormFields("PEPZ").Enabled = False
    425. ActiveDocument.FormFields("PEVP").Enabled = False
    426. ActiveDocument.FormFields("PEVT").Enabled = False
    427. ActiveDocument.FormFields("PEVZ").Enabled = False
    428. ActiveDocument.FormFields("PEN").Enabled = False
    429. ActiveDocument.FormFields("PPPP").Enabled = True
    430. ActiveDocument.FormFields("PPPT").Enabled = True
    431. ActiveDocument.FormFields("PPPZ").Enabled = True
    432. ActiveDocument.FormFields("PPVP").Enabled = True
    433. ActiveDocument.FormFields("PPVT").Enabled = True
    434. ActiveDocument.FormFields("PPVZ").Enabled = True
    435. ActiveDocument.FormFields("PPN").Enabled = True
    436. ActiveDocument.FormFields("PEPP").Result = ""
    437. ActiveDocument.FormFields("PEPT").Result = ""
    438. ActiveDocument.FormFields("PEPZ").Result = ""
    439. ActiveDocument.FormFields("PEVP").Result = ""
    440. ActiveDocument.FormFields("PEVT").Result = ""
    441. ActiveDocument.FormFields("PEVZ").Result = ""
    442. ActiveDocument.FormFields("PEN").Result = ""
    443. End If
    444. End Sub
    445. Private Sub O2C_Click()
    446. If O2C.Value = True Then
    447. O2A.Value = False
    448. O2B.Value = False
    449. ActiveDocument.FormFields("PEPP").Enabled = False
    450. ActiveDocument.FormFields("PEPT").Enabled = False
    451. ActiveDocument.FormFields("PEPZ").Enabled = False
    452. ActiveDocument.FormFields("PEVP").Enabled = False
    453. ActiveDocument.FormFields("PEVT").Enabled = False
    454. ActiveDocument.FormFields("PEVZ").Enabled = False
    455. ActiveDocument.FormFields("PEN").Enabled = False
    456. ActiveDocument.FormFields("PPPP").Enabled = False
    457. ActiveDocument.FormFields("PPPT").Enabled = False
    458. ActiveDocument.FormFields("PPPZ").Enabled = False
    459. ActiveDocument.FormFields("PPVP").Enabled = False
    460. ActiveDocument.FormFields("PPVT").Enabled = False
    461. ActiveDocument.FormFields("PPVZ").Enabled = False
    462. ActiveDocument.FormFields("PPN").Enabled = False
    463. ActiveDocument.FormFields("PEPP").Result = ""
    464. ActiveDocument.FormFields("PEPT").Result = ""
    465. ActiveDocument.FormFields("PEPZ").Result = ""
    466. ActiveDocument.FormFields("PEVP").Result = ""
    467. ActiveDocument.FormFields("PEVT").Result = ""
    468. ActiveDocument.FormFields("PEVZ").Result = ""
    469. ActiveDocument.FormFields("PEN").Result = ""
    470. ActiveDocument.FormFields("PPPP").Result = ""
    471. ActiveDocument.FormFields("PPPT").Result = ""
    472. ActiveDocument.FormFields("PPPZ").Result = ""
    473. ActiveDocument.FormFields("PPVP").Result = ""
    474. ActiveDocument.FormFields("PPVT").Result = ""
    475. ActiveDocument.FormFields("PPVZ").Result = ""
    476. ActiveDocument.FormFields("PPN").Result = ""
    477. End If
    478. End Sub
    479. Private Sub FFJA_Click()
    480. If FFJA.Value = True Then
    481. FFNEIN.Value = False
    482. ActiveDocument.FormFields("FFA").Enabled = True
    483. ActiveDocument.FormFields("SW").Enabled = True
    484. ActiveDocument.FormFields("WR").Enabled = True
    485. ActiveDocument.FormFields("FFWRKST").Enabled = True
    486. ActiveDocument.FormFields("FKWRKST").Enabled = True
    487. ActiveDocument.FormFields("ZWL").Enabled = True
    488. End If
    489. End Sub
    490. Private Sub FFNEIN_Click()
    491. If FFNEIN.Value = True Then
    492. FFJA.Value = False
    493. ActiveDocument.FormFields("FFA").Enabled = False
    494. ActiveDocument.FormFields("SW").Enabled = False
    495. ActiveDocument.FormFields("WR").Enabled = False
    496. ActiveDocument.FormFields("FFWRKST").Enabled = False
    497. ActiveDocument.FormFields("FKWRKST").Enabled = False
    498. ActiveDocument.FormFields("ZWL").Enabled = False
    499. End If
    500. End Sub
    501. Private Sub O4A_Click()
    502. If O4A.Value = True Then
    503. O4B.Value = False
    504. End If
    505. End Sub
    506. Private Sub O4B_Click()
    507. If O4B.Value = True Then
    508. O4A.Value = False
    509. End If
    510. End Sub
    511. Private Sub PEPP_Change()
    512. End Sub
    513. Private Sub PPPP_Change()
    514. End Sub


    Der Zweite Teil welcher die Daten an Excel übertragen soll befindet sich in einem extra Modul Namens Word2Excel.

    Visual Basic-Quellcode

    1. Option Explicit
    2. Private Sub Transfer_Data()
    3. Dim xlApp As Object
    4. Dim xlWBook As Object
    5. Dim fld As FormField
    6. Dim nRow As Long
    7. Dim nCol As Integer
    8. Set xlApp = CreateObject("excel.Application")
    9. Set xlWBook = xlApp.Workbooks.Open(ThisDocument.Path & "\artexGeräteliste.xlsx")
    10. xlWBook.Application.Visible = True
    11. xlWBook.Application.Sheets("Geräteübersicht").Select
    12. nRow = xlWBook.Application.Range("A65536").End(xlUp).Row + 1
    13. 'ActiveDocument.Unprotect
    14. nCol = 4
    15. nInstall = ActiveDocument.FormFields("Gebäude").Result
    16. nEqui = ActiveDocument.FormFields("EquiNr").Result
    17. nTyp = ActiveDocument.FormFields("Typ").Result
    18. nPTB = ActiveDocument.FormFields("PTB").Result
    19. nSNR = ActiveDocument.FormFields("SNR").Result
    20. nFFA = ActiveDocument.FormFields("FFA").Result
    21. nPMBAR = ActiveDocument.FormFields("PMBAR").Result
    22. nVMBAR = ActiveDocument.FormFields("VMBAR").Result
    23. nPVDTNG = ActiveDocument.FormFields("PVDTNG").Result
    24. nVVDTNG = ActiveDocument.FormFields("VVDTNG").Result
    25. nMWRKST = ActiveDocument.FormFields("MWRKST").Result
    26. nProzMed = ActiveDocument.FormFields("ProzMed").Result
    27. xlWBook.Application.Cells(nRow, 2).Value = ActiveDocument.FormFields("Gebäude").Result
    28. xlWBook.Application.Cells(nRow, 3).Value = ActiveDocument.FormFields("EquiNr").Result
    29. xlWBook.Application.Cells(nRow, 4).Value = ActiveDocument.FormFields("Typ").Result
    30. xlWBook.Application.Cells(nRow, 5).Value = ActiveDocument.FormFields("PTB").Result
    31. xlWBook.Application.Cells(nRow, 6).Value = ActiveDocument.FormFields("SNR").Result
    32. xlWBook.Application.Cells(nRow, 7).Value = ActiveDocument.FormFields("FFA").Result
    33. xlWBook.Application.Cells(nRow, 8).Value = ActiveDocument.FormFields("PMBAR").Result
    34. xlWBook.Application.Cells(nRow, 9).Value = ActiveDocument.FormFields("VMBAR").Result
    35. xlWBook.Application.Cells(nRow, 10).Value = ActiveDocument.FormFields("PVDTNG").Result
    36. xlWBook.Application.Cells(nRow, 11).Value = ActiveDocument.FormFields("VVDTNG").Result
    37. xlWBook.Application.Cells(nRow, 12).Value = ActiveDocument.FormFields("MWRKST").Result
    38. xlWBook.Application.Cells(nRow, 13).Value = ActiveDocument.FormFields("ProzMed").Result
    39. ActiveDocument.Fields(1).Select
    40. xlWBook.Close savechanges:=True
    41. ActiveDocument.FormFields("Gebäude").Result = nInstall
    42. ActiveDocument.FormFields("EquiNr").Result = nEqui
    43. ActiveDocument.FormFields("Typ").Result = nTyp
    44. ActiveDocument.FormFields("PTB").Result = nPTB
    45. ActiveDocument.FormFields("SNR").Result = nSNR
    46. ActiveDocument.FormFields("FFA").Result = nFFA
    47. ActiveDocument.FormFields("PMBAR").Result = nPMBAR
    48. ActiveDocument.FormFields("VMBAR").Result = nVMBAR
    49. ActiveDocument.FormFields("PVDTNG").Result = nPVDTNG
    50. ActiveDocument.FormFields("VVDTNG").Result = nVVDTNG
    51. ActiveDocument.FormFields("MWRKST").Result = nMWRKST
    52. ActiveDocument.FormFields("ProzMed").Result = nProzMed
    53. End Sub


    Ich hoffe das mir hier jemand helfen kann.
    Fürs anschauen vielen Dank im Voraus.
    Sehr lineare Programmierung. :D
    Eigentlich weiß man gar nicht so richtig, wo man mit den Ratschlägen anfangen soll ;)


    Mit xlWBook.Application.Cells(nRow, 6) addressierst du eine Zelle im momentan zufällig aktiven Worksheet.
    Sauber wäre ein Konstrukt wie xlWBook.Sheets("Tabelle1").Cells(nRow,6) oder meinetwegen auch xlWBook.Sheets(2).Cells(nRow,6)
    Soviel nur nebenbei.


    obwohl ich meiner Meinung nach deklariert habe dafür immer eine neue Zeile zu verwenden

    Mit nRow = xlWBook.Application.Range("A65536").End(xlUp).Row + 1 suchst du die erste freie Zeile in Spalte 1.
    Da du Spalte 1 nie füllst, wird das immer dieselbe sein.
    Auuserdem ist die fixe Konstante 65535 maximal bis Excel 2003 korrekt.
    Dafür gibt's Properties.

    Mein Vorschlag:
    nRow = xlWBook.Sheets(1).Cells(Rows.Count, 2).End(xlUp).Row + 1
    --
    If Not Program.isWorking Then Code.Debug Else Code.DoNotTouch
    --
    Hallo.

    Ja als Laie kann ich damit leben das meine Programmierung fern von Perfekt ist. :D

    Aber danke für die Korrektur und die Hilfestellung.
    Die Codezeile funktioniert, jedoch bekomme ich sobald die addressierte Zeile gefüllt wurde, den Fehler "Method 'Rows' of object ' _Global' failed", wenn ich versuche eine weitere Zeile zu füllen.
    Gibt es eine Möglichkeit zu bestimmen, das wenn eine Zeile bereits Daten enthält, die nächste freie Zeile gewählt wird?

    Also sagen wir ab Zeile 4 abwärts, wenn keine Daten in Zeile 4 vorhanden sind, wirdZeile 4 gefüllt.
    Sind Daten enthalten, dann Zeile 5. Sind Daten in Zeile 5, dann Zeile 6 usw.

    nRow = xlWBook.Sheets("Geräteübersicht").Cells(Rows.Count, 4).End(xlUp).Row + 1

    Der Code schreibt in Zeile 4 und wenn Zeile 4 belegt ist dann geht er eine Zeile nach unten.
    Beim nächsten ausführen fängt er aber wieder bei 4 an, verursacht dann aber einen Fehler weil ja eine Zeile darunter auch schon belegt ist.
    Zumindest versteh ich das so, muß ja aber nicht viel bedeuten ?( ;)

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „illogic“ ()

    Kannst du deinen Beitrag nochmals überprüfen.
    Du wirfst da Spalten und Zeilen willkürlich durcheinander.
    So gibt das für mich keinen Sinn.

    Edit:
    Method 'Rows' of object ' _Global' failed

    Du rufst den Code aus Word auf?

    Visual Basic-Quellcode

    1. Const xlUp = -4162
    2. Set ws = xlWBook.Sheets("Geräteübersicht")
    3. nRow = ws.Cells(ws.Rows.Count, 4).End(xlUp).Row + 1
    --
    If Not Program.isWorking Then Code.Debug Else Code.DoNotTouch
    --

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von „petaod“ ()

    Sorry, Ja da hab ich was verwechselt. habs abgeändert.

    Genau der Code wird aus Word aufgerufen.
    Man öffnet quasi das Protokoll, trägt alles in die Felder ein, speichert das Dokument ab.
    Vor dem eigentlichen Speichervorgang, jedoch nach der Checkfields Abfrage (Pflichtfelder) soll der Inhalt aus den entsprechenden Formularfeldern an Excel übergeben werden.

    Der Code den du in deinem letzten Beitrag geschrieben hast, gibt einen Run-time error 91: Object variable or With block variable not set.
    Markiert wird dieser Teil des Codes.

    Set ws = xlWBook.Sheets("Geräteübersicht")
    Ohje mein Fehler, ich hab versehentlich

    Quellcode

    1. Set ws = xlWBook.Sheets("Geräteübersicht")

    vor

    Quellcode

    1. Set xlApp = CreateObject("excel.Application")
    2. Set xlWBook = xlApp.Workbooks.Open(ThisDocument.Path & "\artexGeräteliste.xlsx")

    gesetzt.
    Somit wollte er das ausführen bevor er überhaupt das Workbook öffnen konnte. :wacko:

    Hab es korrigiert und jetzt scheint es soweit zu funktionieren.

    Vielen vielen Dank dafür!

    So sieht der Code momentan aus.

    Quellcode

    1. Private Sub Transfer_Data()
    2. Dim xlApp As Object
    3. Dim xlWBook As Object
    4. Dim fld As FormField
    5. Dim nRow As Long
    6. Dim nCol As Integer
    7. Dim ws As Object
    8. Const xlUp = -4162
    9. Set xlApp = CreateObject("excel.Application")
    10. Set xlWBook = xlApp.Workbooks.Open(ThisDocument.Path & "\artexGeräteliste.xlsx")
    11. xlWBook.Application.Visible = True
    12. xlWBook.Application.Sheets("Geräteübersicht").Select
    13. Set ws = xlWBook.Sheets("Geräteübersicht")
    14. nRow = ws.Cells(ws.Rows.Count, 4).End(xlUp).Row + 1
    15. 'ActiveDocument.Unprotect
    16. nCol = 4
    17. nInstall = ActiveDocument.FormFields("Gebäude").Result
    18. nEqui = ActiveDocument.FormFields("EquiNr").Result
    19. nTyp = ActiveDocument.FormFields("Typ").Result
    20. nPTB = ActiveDocument.FormFields("PTB").Result
    21. nSNR = ActiveDocument.FormFields("SNR").Result
    22. nFFA = ActiveDocument.FormFields("FFA").Result
    23. nPMBAR = ActiveDocument.FormFields("PMBAR").Result
    24. nVMBAR = ActiveDocument.FormFields("VMBAR").Result
    25. nPVDTNG = ActiveDocument.FormFields("PVDTNG").Result
    26. nVVDTNG = ActiveDocument.FormFields("VVDTNG").Result
    27. nMWRKST = ActiveDocument.FormFields("MWRKST").Result
    28. nProzMed = ActiveDocument.FormFields("ProzMed").Result
    29. xlWBook.Application.Cells(nRow, 2).Value = ActiveDocument.FormFields("Gebäude").Result
    30. xlWBook.Application.Cells(nRow, 3).Value = ActiveDocument.FormFields("EquiNr").Result
    31. xlWBook.Application.Cells(nRow, 4).Value = ActiveDocument.FormFields("Typ").Result
    32. xlWBook.Application.Cells(nRow, 5).Value = ActiveDocument.FormFields("PTB").Result
    33. xlWBook.Application.Cells(nRow, 6).Value = ActiveDocument.FormFields("SNR").Result
    34. xlWBook.Application.Cells(nRow, 7).Value = ActiveDocument.FormFields("FFA").Result
    35. xlWBook.Application.Cells(nRow, 8).Value = ActiveDocument.FormFields("PMBAR").Result
    36. xlWBook.Application.Cells(nRow, 9).Value = ActiveDocument.FormFields("VMBAR").Result
    37. xlWBook.Application.Cells(nRow, 10).Value = ActiveDocument.FormFields("PVDTNG").Result
    38. xlWBook.Application.Cells(nRow, 11).Value = ActiveDocument.FormFields("VVDTNG").Result
    39. xlWBook.Application.Cells(nRow, 12).Value = ActiveDocument.FormFields("MWRKST").Result
    40. xlWBook.Application.Cells(nRow, 13).Value = ActiveDocument.FormFields("ProzMed").Result
    41. 'ActiveDocument.Protect (wdAllowOnlyFormFields)
    42. ActiveDocument.Fields(1).Select
    43. xlWBook.Close savechanges:=True


    Da wäre noch ein anderes Problem.
    Mit den Zeilen,

    Quellcode

    1. ActiveDocument.FormFields("EquiNr").Result
    etc.
    kann ich ja normale Text Form Felder und Drop Downs auslesen, Legacy Forms, alles was ich mit einem Bookmark versehen kann.
    Ich habe aber auch eine ActiveX Combo Box in das Protokoll eingebaut, die ich ebenfalls auslesen lassen möchte.
    Jedoch hab ich bisher nicht herausfinden können wie ich das anstelle.

    ComboBox1. Value oder Range oder Result etc. haben nicht funktioniert.
    Da gibt es sicher wieder irgend eine Kleinigkeit die ich übersehe. :D
    Da wäre es höchste Zeit, dass du dir mal die Objekte anschaust, die du verwendest.
    F2 ist eine Taste, die Wunder wirkt, wenn du vorher ein Objekt markiert hast.

    Oder auch einfach nur Intellisense nutzen.
    Wenn du Combobox1. eingibst, erscheinen im Editor gleich nach der Eingabe des Punktes alle Properties und Methoden dieses Objekts zur Auswahl.

    Ich habe hier auf dem momentan verwendeten Rechner keine Office-Umgebung zum Testen, aber ich könnte wetten, dass es eine Property Text gibt, die das momentan ausgewählte Element der Combobox enthält.
    Falls ich falsch liege, schau dir einfach das Objekt mal genauer an.
    Dazu könntest du einen Breakpoint setzen und es im Überwachungsfenster des Debuggers anschauen.
    --
    If Not Program.isWorking Then Code.Debug Else Code.DoNotTouch
    --