我有我正在使用的这段代码,在此处的帮助下使它成为 Mac/PC 投诉,但至少现在在我的 PC 上运行完成后,我创建了一个带有公司名称和部件号文件夹的文件夹供以后使用。
Sub MakeFolder()
Dim strComp As String, strPart As String, strPath As String
strComp = Range("A1") ' assumes company name in A1
strPart = CleanName(Range("C1")) ' assumes part in C1
strPath = "C:\Images\"
If Not FolderExists(strPath & strComp) Then
'company doesn't exist, so create full path
FolderCreate strPath & strComp & "\" & strPart
Else
'company does exist, but does part folder
If Not FolderExists(strPath & strComp & "\" & strPart) Then
FolderCreate strPath & strComp & "\" & strPart
End If
End If
End Sub
Function FolderCreate(ByVal path As String) As Boolean
FolderCreate = True
Dim fso As New FileSystemObject
If Functions.FolderExists(path) Then
Exit Function
Else
On Error GoTo DeadInTheWater
fso.CreateFolder path
Exit Function
End If
DeadInTheWater:
MsgBox "A folder could not be created for the following path: " & path & ". Check the path name and try again."
FolderCreate = False
Exit Function
End Function
Function FolderExists(ByVal path As String) As Boolean
FolderExists = False
Dim fso As New FileSystemObject
If fso.FolderExists(path) Then FolderExists = True
End Function
Function CleanName(strName as String) as String
'will clean part # name so it can be made into valid folder name
'may need to add more lines to get rid of other characters
CleanName = Replace(strName, "/","")
CleanName = Replace(CleanName, "-","")
etc...
End Function
现在我试图做的是,如果说客户存在,并且 SO# 文件夹存在,则在同一行的 P. 中创建指向它的链接。
现在如下图所示路径是 C:\Images\Company Name\SO#\
我想在代表行中说的链接是“SO#”的图片,SO# 将替换为行本身的 SO#。然后,当您单击它时,该链接会将您带到资源管理器中的文件夹。
理论上我可以使代码看起来像这样,但我不确定完全......
Option Explicit
Sub Create_a_Link()
Dim wsJAR As Worksheet 'JL Archive
Dim lastrow As Long, fstcell As Long
Set wsJAR = Sheets("JL Archive")
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.EnableEvents = False
End With
With JAR
lastrow = wsJAR.Cells(Rows.Count, "P").End(xlUp).Row
Range("P3:P" & lastrow).Value = Hyperlink("C:\$C3:C" & lastrow \" & "B3:B" & lastrow, "Cellname")
End With
With Application
.ScreenUpdating = True
.DisplayAlerts = True
.EnableEvents = True
End With
但我在这里不断收到错误:
Range("P3:P" & lastrow).Value = Hyperlink("C:\$C3:C" & lastrow \" & "B3:B" & lastrow, "Cellname")
说编译错误:预期的列表分隔符或)
如果有人可以帮助它,将不胜感激......附件是excel表。