VBA从Excel到Word移动形状

我正在尝试创build一个移动字形状的VBAmacros。 例如,当一个用户在Excel中input一个值userform = 43,并克服字形中的形状移动43步骤,我在Excel中试过这个,我成功地使代码,但要移动它的话我没有find我怎么试了很多的东西,但如果有人可以帮助我这个。 这是我的代码

Sub lacro1() rep_count = 0 width_variable = 10 Do DoEvents rep_count = rep_count + 1 width_variable = width_variable + 6 Sheets("Feuil1").Shapes("Connecteur droit 2").Left = Sheets("Feuil1").Range("A2").Value timeout (0.01) Loop Until rep_count = Sheets("Feuil1").Range("A2").Value End Sub Sub timeout(duration_ms As Double) Start_Time = Timer Do DoEvents Loop Until (Timer - Start_Time) >= duration_ms End Sub 

我想要的是根据excel中的值移动位于单词.doc中的形状

这对我有用

 Sub Sample() Dim oWordApp As Object, oWordDoc As Object Dim shp As Object '~~> Establish an Word application object On Error Resume Next Set oWordApp = GetObject(, "Word.Application") If Err.Number <> 0 Then Set oWordApp = CreateObject("Word.Application") End If Err.Clear On Error GoTo 0 oWordApp.Visible = True Set oWordDoc = oWordApp.Documents.Open("C:\Users\Siddharth\Desktop\Sid.Docx") Set shp = oWordDoc.Shapes(1) With shp .Left = 80 .Top = 40 End With End Sub 

截图 在这里输入图像说明