[英]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.