如何在VBA中更改工作簿的文件路径? [英] How can I change the file path of a Workbook in VBA?

查看:71
本文介绍了如何在VBA中更改工作簿的文件路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个正在保存的工作簿.它是以不同工作簿中两个单元格的名称保存的.截至目前,它已自动保存到我计算机上的documents文件夹中.我想将其更改为我选择的文件夹.我猜这应该很简单.到目前为止,这是我的代码:

So I have a Workbook that is being saved. It is being saved under a name from two cells in a different workbook. As of right now, it saves automatically to the documents folder on my computer. I would like to change this to a folder of my choosing. I'm guessing this should be pretty straight-forward. Here's my code so far:

    Dim name As String

    name = Workbooks("Transfer Template").Sheets("Sheet1").Range("B1").Value & "_" & Workbooks("Transfer Template").Sheets("Sheet1").Range("B4").Value
    Windows("Protected_Form.xls").Activate
    ActiveWorkbook.SaveAs Filename:=name

谢谢!

推荐答案

Const MY_PATH As String = "C:\Temp\"
Dim name As String

With Workbooks("Transfer Template").Sheets("Sheet1")
    name = .Range("B1").Value & "_" & .Range("B4").Value
End With    

Workbooks("Protected_Form.xls").SaveAs Filename:= MY_PATH & name

这篇关于如何在VBA中更改工作簿的文件路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆