[英]Using Excel VBA to Open a workbook, copy values from certian cells, save the new form, then close the opened workbook
[英]Excel VBA Open a workbook from dropbox then Save/Close Current Workbook
好的,這是到目前為止我嘗試過的代碼:
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
好的,我想打開一個工作簿。 對於不同的用戶,工作簿路徑可能有所不同,因為我們使用保管箱。 因此它將始終是..... \\ Dropbox \\ SSFiles \\ Estimating 2016.xls
在我的情況下,“ info.json”文件將路徑顯示為:
"C:\\Users\\[USER]\\Dropbox"
它使用雙“ \\”字符。 提供的文章說應該看起來像這樣:
"C:\Users\[USER]\Dropbox"
無論您是哪種情況,此代碼都可以獲取位於任何位置的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.