如何从 Excel VB 中提取我所在的共享点文档库的 URL/路径?

发布于 2024-11-04 01:03:47 字数 958 浏览 2 评论 0原文

我想为在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南烟 2024-11-11 01:03:48

我喜欢使用函数 GetSetting() 和语句 SaveSetting 将此类信息保存到注册表(上次使用的路径等)。

从 SHP 文件夹打开文件时,ActiveWorkbook.Path 以“http://”开头。在这种情况下,您可以将此路径从 Sub Workbook_Open() 过程保存到注册表中以保留 SHP 路径信息。稍后可以使用它向用户提供良好的路径/文件名。

希望有帮助......祝你好运 MikeD

I like to use function GetSetting() and statement SaveSetting 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 a Sub 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文