简体   繁体   English

VBA从Sharepoint打开excel文件并更改名称

[英]VBA Open excel file from Sharepoint with changing name

I am trying to generate some code that will open up an excel file on Sharepoint and copy data into another spreadsheet.我正在尝试生成一些代码,这些代码将在 Sharepoint 上打开一个 excel 文件并将数据复制到另一个电子表格中。 I have been using the below code when the files were saved on my laptop and it worked great, however it does not appear to work when I use hppt for the sharepoint location.当文件保存在我的笔记本电脑上时,我一直在使用下面的代码,它运行良好,但是当我使用 hppt 作为共享点位置时,它似乎不起作用。 I suspect it has to do with the dir function.我怀疑它与 dir 函数有关。 Is there an easy way I can alter the below code so it will work on a sharepoint address?有没有一种简单的方法可以更改以下代码,以便它可以在共享点地址上工作? The name of the excel file will change with a different month each time I run the macro.每次运行宏时,excel 文件的名称都会随着月份的不同而变化。

Dim sourceworkbook As Workbook
Dim currentworkbook As Workbook
Dim FolderPath As String
Dim file As String
Set currentworkbook = ThisWorkbook

FolderPath = ("C:\Users\XXXXXX\Desktop\XX\")
file = Dir("C:\Users\XXXXXX\Desktop\XX\" & "WAS*.xls")
Do While file <> vbNullString
Set sourceworkbook = Workbooks.Open(FolderPath & file)
file = Dir()
Loop
    sourceworkbook.Sheets("ABC").Range("A1:A15").Copy
    currentworkbook.Sheets("END").Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
    Application.CutCopyMode = False
    sourceworkbook.Close SaveChanges:=False

Application.ScreenUpdating = True

I don't know if in your environment you have the necessary kind of authentication, but have you tried mapping the Sharepoint folder location to one of your network drives?我不知道在您的环境中您是否有必要的身份验证,但您是否尝试过将 Sharepoint 文件夹位置映射到您的网络驱动器之一? Then you can you can access your file just as it was in any other folder.然后,您可以像在任何其他文件夹中一样访问您的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM