如何从 Excel VB 中提取我所在的共享点文档库的 URL/路径?
我想为在 Excel 文档库中创建的项目设置文件名。然而,当我尝试用我自己的文件名干扰标准保存时,它想要保存到我的本地机器。如果有必要,我很乐意提供路径,但我真的不想对其进行硬编码。
我可以使用任何属性来解析此信息吗?元数据?模板?
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI Then
Sheets("Purchase Order").Range("Description,VendorInfo,QUANTITY1,PRODUCT1,ITEM1,PRICE1,submitter,ShipVia,Terms,MACRO_ALERT").Interior.ColorIndex = xlColorIndexNone
Sheets("Purchase Order").Range("Location").Interior.Color = RGB(184, 204, 228)
Sheets("Purchase Order").Range("MACRO_ALERT").Value = ""
Dim MyFileName As String
Dim MyFilePath As String
' MyFilePath =“http://server/dept/purchasetracking/” MyFilePath = Application.Path
MyFileName = "PO_" & Format(Now(), "yyyymmdd-hhnnss")
MsgBox (MyFilePath & MyFileName)
ActiveWorkbook.SaveAs 文件名:=MyFilePath &我的文件名',文件格式:= 52 ' ActiveWorkbook.SaveAs 文件名:=MyFileName 结束如果 结束子
I would like to set the filename for an item I create in an Excel Document Library. Howeverm when I try to interfere with the standard save with my own filename, it wants to save to my LOCAL MACHINE. I would happily like to supply the PATH if that is necessary, but I really DONT WANT TO HARD CODE IT.
Are there any properties I can use to parse this info? Meta data? Template?
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If SaveAsUI Then
Sheets("Purchase Order").Range("Description,VendorInfo,QUANTITY1,PRODUCT1,ITEM1,PRICE1,submitter,ShipVia,Terms,MACRO_ALERT").Interior.ColorIndex = xlColorIndexNone
Sheets("Purchase Order").Range("Location").Interior.Color = RGB(184, 204, 228)
Sheets("Purchase Order").Range("MACRO_ALERT").Value = ""
Dim MyFileName As String
Dim MyFilePath As String
' MyFilePath = "http://server/dept/purchasetracking/"
MyFilePath = Application.Path
MyFileName = "PO_" & Format(Now(), "yyyymmdd-hhnnss")
MsgBox (MyFilePath & MyFileName)
ActiveWorkbook.SaveAs Filename:=MyFilePath & MyFileName ', FileFormat:=52
' ActiveWorkbook.SaveAs Filename:=MyFileName
End If
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我喜欢使用函数
GetSetting()
和语句SaveSetting
将此类信息保存到注册表(上次使用的路径等)。从 SHP 文件夹打开文件时,
ActiveWorkbook.Path
以“http://”开头。在这种情况下,您可以将此路径从Sub Workbook_Open()
过程保存到注册表中以保留 SHP 路径信息。稍后可以使用它向用户提供良好的路径/文件名。希望有帮助......祝你好运 MikeD
I like to use function
GetSetting()
and statementSaveSetting
to save such informations to the registry (last used path, etc.).When the file is opened from a SHP folder,
ActiveWorkbook.Path
starts with "http://". In this case you could save this path from aSub Workbook_Open()
procedure into the registry to retain the SHP path information. This can be later on used to offer a good path/filename to the user.Hope that helps .... Good Luck MikeD