Tag: 绝对path

VBA脚本保存文件,以纠正从一台计算机,而不是其他人的path

我有一个自动化的Excel工作表,下面的脚本是function的一部分。 当我单击工作表上的button时,它将完全保存到path中,并通过电子邮件发送给下一个要查看的人员。 从另一台计算机运行时,不会将其保存到path中。 请注意,我已经删除了error handling程序。 删除之前,它仍然会通过电子邮件附件,但不会保存到其他计算机的path。 所有用户都可以完全访问该文件夹。 代码在工作表中。 如果我把它放在一个模块中,点击button什么都不会发生。 debugging显示模块卡在saveas filepath部分。 任何帮助是极大的赞赏。 谢谢 Private Sub CommandButton1_Click() If WorksheetFunction.CountA(Range("$A27:$O32")) = 0 Then MsgBox "Order has no accessories. Please submit to Distribution.", vbOKOnly Exit Sub End If Dim objOutlook As Outlook.Application Dim objOutlookMsg As Outlook.MailItem Dim objOutlookRecip As Outlook.Recipient Dim objOutlookAttach As Outlook.Attachment Dim TheAddress As String […]

VBA代码修改麻烦

我有Excel文件,它有一个VB代码,它看起来像这样: Sub UPISIVANJE_IZ_CELIJA_U_FILE() Dim iCntr Dim strFile_Path As String strFile_Path = "C:\script generator v1.1\start.bat" Open strFile_Path For Output As #2 For iCntr = 1 To 10041 Print #2, Range("E" & iCntr) Next iCntr Close #2 End Sub 代码工作没有任何问题。 我遇到的麻烦是start.bat文件的位置。 我想要在Excel工作簿文件所在的位置生成此文件。 我试着用这个: strFile_Path = ".\start.bat" 但是,这当然不起作用。

excel文件不保存到macros指定的文件path

我有一个简单的macros,我想每天使用,它工作得很好,而不是保存在我想要的地方。 而不是保存在所需的共享networking文件夹中,而是保存在“文档”文件夹中。 请帮忙。 Dim FilePath As String Dim NewName As String FilePath = "G:\Pricing\Gas Pricing Models\Wholesale\Basis Strips": NewName = "NYMEX" & Format(Date, "MM-DD-YYYY") & ".xlsm" ActiveWorkbook.SaveAs Filename:=NewName, FileFormat _ :=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False ActiveWindow.SmallScroll Down:=-30 End Sub

在长path名称的Excel上的Shell命令不起作用

我有一个batch filerun.bat在networking文件夹“L:\ Common Data \ myfile”,我想从Excel的macros执行它。 谷歌search我发现这些sintax: Call Shell(Environ$("COMSPEC") & " /k L:\Common Data\myfile\run.bat", vbNormalFocus) 但由于只读取“L:\ Common”而失败。 我尝试了很多在互联网上发现的build议,但没有人成功。 有人有解决scheme?

在vba中设置FilePath和FileName

好吧,我想我已经弄糊涂了,怎么做,也许我做了一些明显的错误? 这是我的代码: Private Sub CommandButton1_Click() Dim wbI As Workbook, wbO As Workbook, wb1 As Workbook Dim wsI As Worksheet, wsO As Worksheet, ws1 As Worksheet filelocation1 = "C:\Users\Public\Desktop_" & Format(Date, "ddmmyyyy") & "Production.xls" Set wbI = ThisWorkbook Set wsI = wbI.Sheets("Production") Set wbO = Workbooks.Add With wbO Set wsO = wbO.Sheets("Sheet1") *****ActiveWorkbook.SaveAs Filename:=filelocation1 wsI.Range("A1:C100").Copy wsO.Range("A1").PasteSpecial […]

通过服务器上的代码运行macros:错误的path到Excel文件?

在我的应用程序中,我打开一个带有macros(将数据复制到.xlsm文件)的.xlsm文件和一个执行该macros的.xlsx文件。 假设我的文件被称为FileWithMacro.xlsm和FileThatExecutesMacro.xlsx 。 我需要在服务器上的这个应用程序,但已经在本地开发。 为了debugging应用程序,我把我的文件放到C:\Users\myUser\Documents\ 。 我打开这样的FileWithMacro.xlsm : Excel.Application excel = new Excel.Application(); Excel.Workbook workbook = excel.Workbooks.Open(serverPath + "FileWithMacro.xlsm"); Excel._Worksheet worksheet = workbook.Sheets["FileThatExecutesMacro"]; 之后,我调用运行macros的方法: RunMacro(serverPath + "FileThatExecutesMacro.xlsx"); 我的方法如下所示: private static void RunMacro(string source) { Excel.Application excel = new Excel.Application(); Excel.Workbook workbook = excel.Workbooks.Open(source); Excel._Worksheet worksheet = workbook.Sheets[1]; worksheet.Activate(); try { excelThatRunsMacro.Run("FileWithMacro.xlsm!MyMacro"); workbook.Save(); excelThatRunsMacro.Quit(); } // […]

在excel vba中使用超链接的path名中的#号

我正在创build一个vba For循环来遍历一个范围内的单元格,并根据单元格内的文本创build一个到文件夹的超链接。 见下文: Set rng = Worksheets("Sheet1").Range("A1:A100") For Each cell In rng address1 = "C:\Users\Desktop\Tests\Comm Review\Item #" & cell.Text If Not IsEmpty(cell) Then Worksheets("Sheet1").Hyperlinks.Add Anchor:=cell, Address:=address1, TextToDisplay:=cell.Text End If Next cell 单元格值将类似于1001.T0502和我链接到的实际文件夹名称将项目#1001.T0502。 所以在我的address1variables我创build文件夹的path。 但是,当我这样做的时候,它创build了一切,但#1001.T0502,并最终停在“\ Item”的path。 如果我要删除号码(#),尽pipe它包含号码,最后成为项目1001.T0502。 由于某种原因,数字符号阻止了它制作正确的path。 我在这里错过了什么? 已经有200个文件夹名称中带有数字标记的文件夹,所以现在回去拿出来将是太多的工作。 任何帮助,将不胜感激。 谢谢!

如何使用VBA中的单元格的文件path?

我正在运行VBA脚本,以便对选定文件夹中每个文件中的行数进行计数,然后将其显示在活动的工作簿中。 Option Explicit Sub CountRows() Dim wbSource As Workbook, wbDest As Workbook Dim wsSource As Worksheet, wsDest As Worksheet Dim strFolder As String, strFile As String Dim lngNextRow As Long, lngRowCount As Long Application.ScreenUpdating = False Set wbDest = ActiveWorkbook Set wsDest = wbDest.ActiveSheet strFolder = Dir(Range("C7").Value) strFile = Dir(strFolder & "*.xlsx") lngNextRow = 11 […]

如何要求excel 2010工作簿在特定的文件path中以打开VBA?

我想要求工作簿位于打开的特定文件path中。 我在Excel 2010中使用VBA。 (Project / ThisWorkbook code:Header:Workbook / Open) Private Sub Workbook_Open FilePath 'Runs file path check when workbook opened End Sub (项目/模块/模块1标题:(一般)FilePath) Sub FilePath() If ActiveWorkbook.Path = ("path address") Then PathOk Else MsgBox ("This is an Unauthorized copy of this file. Please contact Administrator"), vbOKOnly ActiveWindow.Close SaveChanges:=False Exit Sub End If End Sub 问题是工作簿当前打开并运行PathOk […]

Python os.isfile不尊重excel文件

ipdb> os.listdir(SPREADSHEETS_DIR) ['Report Mar.xlsx'] ipdb> fff = os.listdir(SPREADSHEETS_DIR)[0] ipdb> fff 'Report Mar.xlsx' ipdb> os.path.isfile(fff) False 这是为什么? 我知道我可以检查扩展名,但不是os.path.isfile应该与这样的文件?