von MoD » Fr, 25.03.2011 10:53
So.. nun bin ich auch mal wieder an dem Makro-Problem dran..
Folgendes:
aus dem Intranet wird eine Kopfbogen-Word-Vorlage geladen. In diese werden dann per VBA Makro automatisch der aktuelle Benutzer, Datum, Stellenzeichen, Emailadresse, Telefon, usw. was alles in einer Datei die auf den Server hinterlegt ist und regelmäßig aktualisiert wird, eingetragen.
Das Original in VBA sieht so aus:
Code: Alles auswählen
'Aktualisierung der Bearbeiterinformation
'Vers. 1.0
Option Explicit
Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
Public Sub MAIN()
Dim Globuname As String
Dim L&, Ergebnis&, Fehler&
Dim User$, UserName$, Puffer$
Dim Str1 As String 'Benutzerkonto
Dim StartStr As String
Dim LenStr1
Dim x As Integer
Dim x2 As Integer
Dim y As Integer
Dim Back1 As String 'Nachname
Dim Back2 As String 'Vorname
Dim Back3 As String 'GZ
Dim Back4 As String 'Zimmer
Dim Back5 As String 'Telefonnummer
Dim Back6 As String 'EMail-Adresse
Dim Back7 As String 'Faxnummer
Dim Back8 As String 'Ort
Dim Back9 As String 'Plz
Dim Back10 As String 'Strasse
Dim Back(1 To 10) As String
Dim Datum As String
Dim Pfad As String
Datum = Left(Now, 10) 'aktuelles Datum einlesen.
User = Space(255)
L = 255
Ergebnis = GetUserName(User, L)
If Ergebnis <> 0 Then
UserName = Left(User, L - 1)
End If
Globuname = Trim$(UserName)
'If Len(Globuname) > 20 Then Globuname = Left$(Globuname, 20)
StartStr = (Len(Globuname))
Pfad = "p:\BeaInfo\bea.txt" 'Pfad zur Textdatei
Open Pfad For Input Access Read As #1 'Offnet die Textdatei zum lesen
'***Ermitteln des UserNames in der Textdatei
Do While Not EOF(1)
Line Input #1, Str1 'kompletten String einlesen
If Left(Str1, StartStr) = Globuname Then
Exit Do
End If
Loop
'***
Close #1
LenStr1 = Len(Str1) 'Stringlänge ermitteln
'***Name und Vorname durch Komma getrennt. Komma ermitteln
For x = x To LenStr1 - 1
y = 1
If Mid(Str1, StartStr + x, 1) = "," Then
Back1 = Mid(Str1, StartStr + 2, x - 2) 'Zeichen bis zum Komma zurückgeben
'Stop
StartStr = StartStr + x + 1 'Neuer Startwert für die 2. For-Schleife
'Stop
Exit For 'Nach Kommafund beenden
End If
Next x
'***
'*** 2. Schleife sucht nach Tabstopps und liest den bis dahin gefundenen String in eine Variable
For x = x To LenStr1 - 1
x2 = x2 + 1
If Mid(Str1, StartStr + x2, 1) = vbTab Then
y = y + 1
Back(y) = Mid(Str1, StartStr + 1, x2 - 1)
StartStr = StartStr + x2
x2 = 0
'Stop
'MsgBox Back(y)
'Exit For
End If
Next x
'Stop
'MsgBox Back1 + vbCrLf + Back(2) + vbCrLf + Back(3) + vbCrLf + Back(4) + vbCrLf + Back(5)
Selection.GoTo What:=wdGoToBookmark, Name:="Bearbeiter" 'Vor und Nachname
With Selection.Frames(1)
.Width = CentimetersToPoints(15.31)
End With
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=Back(2) + Chr(32) + Back1
Selection.GoTo What:=wdGoToBookmark, Name:="GZ" 'Geschäftszeichen
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=Back(3)
Selection.GoTo What:=wdGoToBookmark, Name:="Zimmer" 'Zimmer
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=Back(4)
Selection.GoTo What:=wdGoToBookmark, Name:="TelNr" 'Telefonnummer
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=Back(5)
Selection.GoTo What:=wdGoToBookmark, Name:="Email" 'Email-Adresse
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=Back(6)
Selection.GoTo What:=wdGoToBookmark, Name:="FaxNr" 'Fax-Nummer
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=Back(7)
Selection.GoTo What:=wdGoToBookmark, Name:="Plz" 'Plz und Ort
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=Back(9) + Chr(32) + Back(8)
Selection.GoTo What:=wdGoToBookmark, Name:="Strasse" 'Strasse
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=Back(10)
With Selection.Frames(1)
.Width = CentimetersToPoints(5.31)
End With
'***aktuelles Datum wird z.Z. nicht gewünscht.
'Selection.GoTo What:=wdGoToBookmark, Name:="Datum"
'Selection.TypeText Text:=Datum
'****9(0) durch 90 ersetzen
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "9(0)"
.Replacement.Text = "90"
End With
Selection.Find.Execute Replace:=wdReplaceAll
'9(0) durch 90 ersetzen****
Selection.GoTo What:=wdGoToBookmark, Name:="Start"
End Sub
Ich weiß ja das sich hier niemand die Mühe machen wird, mir das in BASIC umzuschreiben.. aber kann mir bitte wenigstens jemand sagen, ob es überhaupt möglich ist?
Bzw würde es mir jemand für ein kleines Endgeld umschreiben?
Gruß
MoD
So.. nun bin ich auch mal wieder an dem Makro-Problem dran..
Folgendes:
aus dem Intranet wird eine Kopfbogen-Word-Vorlage geladen. In diese werden dann per VBA Makro automatisch der aktuelle Benutzer, Datum, Stellenzeichen, Emailadresse, Telefon, usw. was alles in einer Datei die auf den Server hinterlegt ist und regelmäßig aktualisiert wird, eingetragen.
Das Original in VBA sieht so aus:
[code]'Aktualisierung der Bearbeiterinformation
'Vers. 1.0
Option Explicit
Private Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" (ByVal lpBuffer As String, _
nSize As Long) As Long
Public Sub MAIN()
Dim Globuname As String
Dim L&, Ergebnis&, Fehler&
Dim User$, UserName$, Puffer$
Dim Str1 As String 'Benutzerkonto
Dim StartStr As String
Dim LenStr1
Dim x As Integer
Dim x2 As Integer
Dim y As Integer
Dim Back1 As String 'Nachname
Dim Back2 As String 'Vorname
Dim Back3 As String 'GZ
Dim Back4 As String 'Zimmer
Dim Back5 As String 'Telefonnummer
Dim Back6 As String 'EMail-Adresse
Dim Back7 As String 'Faxnummer
Dim Back8 As String 'Ort
Dim Back9 As String 'Plz
Dim Back10 As String 'Strasse
Dim Back(1 To 10) As String
Dim Datum As String
Dim Pfad As String
Datum = Left(Now, 10) 'aktuelles Datum einlesen.
User = Space(255)
L = 255
Ergebnis = GetUserName(User, L)
If Ergebnis <> 0 Then
UserName = Left(User, L - 1)
End If
Globuname = Trim$(UserName)
'If Len(Globuname) > 20 Then Globuname = Left$(Globuname, 20)
StartStr = (Len(Globuname))
Pfad = "p:\BeaInfo\bea.txt" 'Pfad zur Textdatei
Open Pfad For Input Access Read As #1 'Offnet die Textdatei zum lesen
'***Ermitteln des UserNames in der Textdatei
Do While Not EOF(1)
Line Input #1, Str1 'kompletten String einlesen
If Left(Str1, StartStr) = Globuname Then
Exit Do
End If
Loop
'***
Close #1
LenStr1 = Len(Str1) 'Stringlänge ermitteln
'***Name und Vorname durch Komma getrennt. Komma ermitteln
For x = x To LenStr1 - 1
y = 1
If Mid(Str1, StartStr + x, 1) = "," Then
Back1 = Mid(Str1, StartStr + 2, x - 2) 'Zeichen bis zum Komma zurückgeben
'Stop
StartStr = StartStr + x + 1 'Neuer Startwert für die 2. For-Schleife
'Stop
Exit For 'Nach Kommafund beenden
End If
Next x
'***
'*** 2. Schleife sucht nach Tabstopps und liest den bis dahin gefundenen String in eine Variable
For x = x To LenStr1 - 1
x2 = x2 + 1
If Mid(Str1, StartStr + x2, 1) = vbTab Then
y = y + 1
Back(y) = Mid(Str1, StartStr + 1, x2 - 1)
StartStr = StartStr + x2
x2 = 0
'Stop
'MsgBox Back(y)
'Exit For
End If
Next x
'Stop
'MsgBox Back1 + vbCrLf + Back(2) + vbCrLf + Back(3) + vbCrLf + Back(4) + vbCrLf + Back(5)
Selection.GoTo What:=wdGoToBookmark, Name:="Bearbeiter" 'Vor und Nachname
With Selection.Frames(1)
.Width = CentimetersToPoints(15.31)
End With
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=Back(2) + Chr(32) + Back1
Selection.GoTo What:=wdGoToBookmark, Name:="GZ" 'Geschäftszeichen
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=Back(3)
Selection.GoTo What:=wdGoToBookmark, Name:="Zimmer" 'Zimmer
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=Back(4)
Selection.GoTo What:=wdGoToBookmark, Name:="TelNr" 'Telefonnummer
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=Back(5)
Selection.GoTo What:=wdGoToBookmark, Name:="Email" 'Email-Adresse
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=Back(6)
Selection.GoTo What:=wdGoToBookmark, Name:="FaxNr" 'Fax-Nummer
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=Back(7)
Selection.GoTo What:=wdGoToBookmark, Name:="Plz" 'Plz und Ort
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=Back(9) + Chr(32) + Back(8)
Selection.GoTo What:=wdGoToBookmark, Name:="Strasse" 'Strasse
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.TypeText Text:=Back(10)
With Selection.Frames(1)
.Width = CentimetersToPoints(5.31)
End With
'***aktuelles Datum wird z.Z. nicht gewünscht.
'Selection.GoTo What:=wdGoToBookmark, Name:="Datum"
'Selection.TypeText Text:=Datum
'****9(0) durch 90 ersetzen
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "9(0)"
.Replacement.Text = "90"
End With
Selection.Find.Execute Replace:=wdReplaceAll
'9(0) durch 90 ersetzen****
Selection.GoTo What:=wdGoToBookmark, Name:="Start"
End Sub
[/code]
Ich weiß ja das sich hier niemand die Mühe machen wird, mir das in BASIC umzuschreiben.. aber kann mir bitte wenigstens jemand sagen, ob es überhaupt möglich ist?
Bzw würde es mir jemand für ein kleines Endgeld umschreiben?
Gruß
MoD