vba Excel 2010 Environ(“用户名")在saveas文件路径中不起作用 [英] vba excel 2010 Environ("username") not working in saveas filepath

查看:270
本文介绍了vba Excel 2010 Environ(“用户名")在saveas文件路径中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我可以得到消息框来告诉我用户名是什么,但是在另存为"路径中它的工作方式不同.我收到找不到路径"错误.

For some reason I can get the Message Box to tell me what the username is, but it doesn't work the same way within the save as path. I get a "Cannot find path" error.

不确定如何解决此问题.我还查看了参考文献,它们似乎是正确的.

Not sure how to fix this. I've also looked at references, and they seem like they are correct.

如果我更改路径以包括每台计算机的实际用户名,则宏可以正常工作.但是我需要将其作为任何计算机/用户的全局宏.任何帮助将不胜感激.

If I change the path to include the actual username per computer, the macro works fine. But I need this to be a global macro for any computer/user. Any help would be greatly appreciated.

这就是我所拥有的:

Sub SAVEAS_2010()
'
' SAVEAS_2010 Macro
MsgBox Environ("username")

Dim UserName As String
UserName = Environ("username")

ChDir "C:\Users\" & UserName & "\Dropbox\Open Machine Schedule"
ActiveWorkbook.SaveAs FileName:= _
    "C:\Users\" & UserName & "\Dropbox\Open Machine Schedule\Open Machine Schedule - Current_2.xlsx" _
    , FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
End Sub

推荐答案

或者您也可以将VBA.放在它前面.这为我解决了. 即Environ("Username")变为VBA.Environ("Username").

Or you could just put VBA. in front of it. This fixes it for me. i.e. Environ("Username") becomes VBA.Environ("Username").

这篇关于vba Excel 2010 Environ(“用户名")在saveas文件路径中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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