excel 文件图像在不同的PC上无法自动更新[已关闭]

pu82cl6c  于 2023-03-31  发布在  其他
关注(0)|答案(1)|浏览(120)

**已关闭。**此问题为not reproducible or was caused by typos。当前不接受答案。

这个问题是由打字错误或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
2天前关闭。
Improve this question
下面是我的代码放置图像从一个指定的文件夹使用的用户名。

Sub GetPic()
Dim fNameAndPath As String
Dim img As Object
Dim CommodityName1 As String, T1 As String
Dim myDir As String
Dim i As Integer, j As Integer
Worksheets("Picture").Activate
Dim shape As Excel.shape
Dim datarangeb As Range
Dim numberofcells As Integer
'Declare variable
    Dim strUserName As String
    'Get system logged in user name
    strUserName = Environ("Username")
    'Display the user name on sheet1
    

Set datarangeb = Sheets("Data").Range("b:b")

numberofcells = WorksheetFunction.CountA(datarangeb)
numberofcells = (numberofcells - 1) * 12 + 1

For Each shape In ActiveSheet.Shapes
        shape.Delete
Next

j = 7

For i = 2 To numberofcells

myDir = "C:\Users\" & strUserName & "\Villaron\SBP Admin Sales - Documents\Clients\00 - Estimating Register\rebar shapes" & "\"
CommodityName1 = Range("a" & i)

T1 = ".png"

fNameAndPath = myDir & CommodityName1 & T1



    Set img = ActiveSheet.Pictures.Insert(fNameAndPath)
  
    With img
       'Move and Resize Image
       .ShapeRange.LockAspectRatio = msoFalse
       .Left = ActiveSheet.Range("d" & i).Left
       .Top = ActiveSheet.Range("d" & i).Top
       .Width = ActiveSheet.Range("d" & i & ":g" & i).Width
       .Height = ActiveSheet.Range("d" & i & ":g" & j).Height
       
       
          .Width = .Width - 10
       .Height = .Height - 5
       .Left = .Left + 5
       
errormessage:
If Err.Number = 1004 Then
Exit Sub
MsgBox "File does not exist." & vbCrLf & "Check the name of the rebar!"
End If
       
    End With
    

Application.ScreenUpdating = True

i = i + 11
 j = j + 12
Next i

i = i - 1

Worksheets("Picture").Range("A" & i & ":i27000").Clear
Worksheets("Picture").Range("A" & i & ":i27000").ClearFormats
  
End Sub

它适用于我的电脑,但不适用于其他人.我已经把图像到OneDrive,每个人都可以访问工作文件.所以文件路径fNameAndPath既有用户名和特定的一个驱动器文件夹.但对于网络上的电脑,它不正确显示

我已经在另一台电脑上禁用了宏安全功能的情况下测试了它,但它仍然不起作用。对fNameAndPath可能有什么问题有什么想法吗?

相关问题