我想要一个Word宏,它将插入动态签名(最多三个)并且之前从未做过任何VBA(更多的是Powershell家伙......)。
为此,我在“开发人员”界面中创建了一个UserForm,其中包含3个框架和大量单选按钮,其中包含能够签名的人员姓名。
由于有60个人(或更多)能够签名,我想到了一个包含“名称,部门,功能”的CSV文件。
我的问题是我不知道如何读取CSV,将其与我的标题(比如Caption =“Jon Swiss”)进行比较,并为其他三个值初始化变量。
我用一些书签标记了我的文档(仅适用于标题)。
我不知道你是否需要我做过的脚本(没有关于CSV的内容 - 对不起......)
Private Sub RHBtn_Accepter_Click_Click()
'Initialisation
Dim i As Integer
'***
' Signature 1
'***
'Pour chaque valeur possible
For i = 1 To Me.Controls.Count
'Si i plus petit que le nombre de valeur définie
If i < Me.Controls.Count Then
Set MyControl = Me.Controls.Item(i)
'Si control dispose du tag RHSign1
If MyControl.Tag = "RHSign1" Then
'Si une valeur est activée
If MyControl.Value = True Then
'Mise en variable du nom en Sign1
RHSignature1 = MyControl.Caption
Exit For
End If
End If
End If
Next i
'***
' Gettings CSV Value
'***
'***
' Tagging the bookmarks
'***
If ActiveDocument.Bookmarks.Exists("RhSignet1") = True Then
Selection.GoTo What:=wdGoToBookmark, Name:="RhSignet1"
Selection.TypeText Text:=RHSignature1
End If
End Sub
谢谢您的帮助。
我找到了一种使用CSV的方法。
'Répertoire
directory = "H:\@SCRIPTS\VBA_MacroWord_DigitRH\"
FileName = "BaseSignatureTest.csv"
'Ouverture de la connexion CSV
Set rs = CreateObject("ADODB.Recordset")
strcon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & directory & ";" _
& "Extended Properties=""text;HDR=Yes;FMT=Delimited"";"
strSQL = "SELECT * FROM " & FileName
rs.Open strSQL, strcon, 3, 3
rs.MoveFirst
Do
col1 = rs("Nom")
col2 = rs("Fonction")
col3 = rs("DPT")
col4 = rs("Signature")
rs.MoveNext
'Si une valeur a été trouvée et qu'elle corresponds, définition des valeurs
If col1 = RHSignature2 Then
MsgBox "Signature2"
MsgBox col1
MsgBox col2
MsgBox col3
MsgBox col4
似乎工作。也许有更好的方法。但感谢大家花了一些时间花时间来读我。祝你好一周,乔恩