[英]Excel VBA Open a workbook from dropbox then Save/Close Current Workbook
Ok here is the code I have tried so far: 好的,这是到目前为止我尝试过的代码:
Dim myFileName As String, DTAddress As String, ans As String, DBPathEstim As String
Dim sPath As String, stPath As String, WB1 As Workbook, WB2 As Workbook, OriginFile As String
' Send the workbook to clients
myFileName = Worksheets("EstimatingSheet").Range("U11").Value & ".xls"
sPath = ActiveWorkbook.Path
stPathClients = Left(sPath, InStrRev(sPath, "\") - 1) & "\Clients\" & myFileName
ActiveWorkbook.SaveAs stPathClients
ActiveWorkbook.Close
Ok I would like to open a workbook. 好的,我想打开一个工作簿。 The work book path may be different for different users because we use dropbox. 对于不同的用户,工作簿路径可能有所不同,因为我们使用保管箱。 So it will always be .....\\Dropbox\\SSFiles\\Estimating 2016.xls 因此它将始终是..... \\ Dropbox \\ SSFiles \\ Estimating 2016.xls
In my case the "info.json" file shows the path as: 在我的情况下,“ info.json”文件将路径显示为:
"C:\\Users\\[USER]\\Dropbox"
It uses double "\\" characters. 它使用双“ \\”字符。 The article provided says it should appear like this: 提供的文章说应该看起来像这样:
"C:\Users\[USER]\Dropbox"
Whatever your case is, this code works to get the Dropbox path wherever is located: 无论您是哪种情况,此代码都可以获取位于任何位置的Dropbox路径:
Function GetDropboxPath() As String
'---------------------------------------------------------------------------------'
'* Locates the Dropbox user path by usign the local "info.json" file. ************'
'* Wrote by cesarmades ***********************************************************'
'---------------------------------------------------------------------------------'
' Loads the local info.json file
Dim intFile As Integer: intFile = FreeFile
Open VBA.Interaction.Environ("USERPROFILE") & "\AppData\Local\Dropbox\info.json" For Input As #intFile
' Stores info.json file content in a variable
Dim strFileContent As String: strFileContent = Input(LOF(intFile), intFile)
Close #intFile
' Trims the string and returns the path
Dim intIPos As Integer: intIPos = VBA.Strings.InStr(1, strFileContent, """path""", vbTextCompare) + 9
Dim intFPos As Integer: intFPos = VBA.Strings.InStr(1, strFileContent, """host""", vbTextCompare) - 3
GetDropboxPath = VBA.Strings.Replace(Mid(strFileContent, intIPos, intFPos - intIPos), "\\", "\")
End Function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.