vba另存为pdf到与其他计算机共享的文件夹中 [英] vba save as pdf into a shared folder with different computer

查看:74
本文介绍了vba另存为pdf到与其他计算机共享的文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我写了一个代码,将excel表作为PDF文件保存到我们公司的共享文件夹(投递箱)中.我意识到当我的同事尝试使用该宏时,由于文件的保存路径,该宏无法正常工作.

Hi I wrote a code where it saves the excel sheet as PDF file into a our company's sharefolder (dropbox). I realized when my coworker tried to use that Macro, it doesn't work because of the path the file is saved.

代码中的"MyComputerName"是我的计算机名称,我猜是因为我的同事计算机名称不同,所以无法在她的计算机上找到路径.

in the code, where it says "MyComputerName" is what my computer name and i am guessing it's because my co workers computer name is different so it can't find the path on her computer.

有没有办法解决这个问题?所以我们俩都可以使用此宏并将其保存到共享文件夹中?

Is there a way to solve this? so we both can use this macro and save it into the shared folder ?

帮助!

Sub SaveAsPDF()

' FormatName
ActiveSheet.Name = "#" & ActiveSheet.Range("F6").Value & " " & ActiveSheet.Range("F4").Value

' saveAsPDF Macro   
ActiveSheet.ExportAsFixedFormat Type:=xltypepdf, Filename:= _
  "C:\Users\MyComputerName\Dropbox\Team Folder\PACKING LIST\201804\" & "PACKING LIST_" & ActiveSheet.Name _
    , quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
    :=False, OpenAfterPublish:=True
End Sub

推荐答案

尝试将以下行添加到代码的开头:

Try adding the following lines to the beginning of your code:

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

然后您的路径应该是:

"C:\Users\" & username & "\Dropbox\...

要使年/月动态(假设基于今天的日期),您的链接可以是:

To make the year/month dynamic (assuming based on today's date), your link can be:

...LIST\" & Format(Now(), "yyyymm") & "\PACKING LIST...

这篇关于vba另存为pdf到与其他计算机共享的文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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