excel-vba

Replace hard-code path with dynamic path of vbscript

南笙酒味 提交于 2020-01-02 09:55:10
问题 I have a vbscript that opens a workbook and runs a procedure in the module1 of the workbook, then closes the workbook. Works great. But here's the thing. The path to the workbook is hard coded, like this: Set xlBook = xlApp.Workbooks.Open("E:\FolderName\WorkbookName.xlsm", 0, True) I don't mind requiring the user to have the script and the workbook in the same folder, and requiring that they not change the name of the workbook file, but I'd like to just substitute the hard coded path with

How to avert the save MessageBox prompt in Excel-VBA?

大城市里の小女人 提交于 2020-01-02 09:39:08
问题 I have a problem here if you look at my codes below after I call the .close line which was the file I initially copied from. It will prompt a save MessageBox message either yes, no, or cancel. Is there anyway I can avoid this save message from appearing programmatic if no was the case could I just programmatic program it no instead? 回答1: Jon is right to suggest Application.DisplayAlerts and if you want to answer no to a save as you suggest Workbooks(Filename1).Close SaveChanges:=False 回答2:

Close excel application using Powershell

只愿长相守 提交于 2020-01-02 09:21:13
问题 I am initiating a macro in a workbook from powershell (to automate a process). The below in powershell opens the excel workbook and runs the macro without visualizing the process. The issue is even though I do not see the macro running, the new instance of excel generated from the macro is still open. # start Excel $excel = New-Object -comobject Excel.Application #open file $FilePath = 'C:\file\Book1.xlsm' $workbook = $excel.Workbooks.Open($FilePath) #access the Application object and run a

Is there a macro to conditionally copy rows to another worksheet?

梦想与她 提交于 2020-01-02 07:20:16
问题 Is there a macro or a way to conditionally copy rows from one worksheet to another in Excel 2003? I'm pulling a list of data from SharePoint via a web query into a blank worksheet in Excel, and then I want to copy the rows for a particular month to a particular worksheet (for example, all July data from a SharePoint worksheet to the Jul worksheet, all June data from a SharePoint worksheet to Jun worksheet, etc.). Sample data Date - Project - ID - Engineer 8/2/08 - XYZ - T0908-5555 - JS 9/4/08

How to return unique value from a range of values Excel VBA

十年热恋 提交于 2020-01-02 07:08:25
问题 I have a table with three fields (ID, Price, Date) in excel. It has four records as following: ID Price Date 1 $400 1/1/2010 2 $500 1/2/2010 3 $200 1/1/2010 4 $899 1/2/2010 I would like to take each value of the date and place it in a cell A2 , A3 , A4 .... however, I want to take only unique dates and do not take any date that was already stored in a previous cell. For example, date 1/1/2010 should be stored in cell A2 and 1/2/2010 should be stored in cell A3 . When it comes to the third

Excel VBA If cell.Value =… then

纵饮孤独 提交于 2020-01-02 06:18:11
问题 I have this code which works well: Sub colortest() Dim cell As Range For Each cell In Range("Range1") If cell.Value = "Word1" Then cell.Interior.Color = XlRgbColor.rgbLightGreen ElseIf cell.Value = "Word2" Then cell.Interior.Color = XlRgbColor.rgbOrange ElseIf cell.Value = "Word3" Then cell.Interior.Color = XlRgbColor.rgbRed End If Next cell End Sub My problem is the values work only if the cell contains only that text. But my cells are usually like this: "Something, 10254, 15/15, Word1

saving csv from excel loses decimal point precision

冷暖自知 提交于 2020-01-02 05:59:12
问题 If I create a simple .csv file containing something like this: 01/22/2013,3.14159265358979323846264338 and proceed to open it up in excel, the cell will show a rounded number i.e. 3.141592654 and the formula bar will show the whole value. However if I make some changes and save the csv file, or just save the original file as a different csv file, the file will only contain the rounded number 3.141592654 , causing me to lose some decimal point precision. I am writing these files out via a vba

Evaluate Excel VBA boolean condition (not a formula)

两盒软妹~` 提交于 2020-01-02 05:54:46
问题 I have text in a cell A1 as below ((True And False Or True) And (True And (Not True))) And (False Or True) I need to evaluate this text and put Boolean result (True / False) in another cell B1 using VBA code . I tried to use Evaluate function, it is not working. When I read this cell, it always return string type with double quote enclose in both side. Hence it is treated as string and not evaluating the Boolean expression. "((True And True Or True) And (True And (True))) And (True Or True)"

How can I append specific pages from one pdf to another pdf?

主宰稳场 提交于 2020-01-02 05:36:22
问题 Currently I have code which combines pdfs together. It takes all pages from each file I specify in Column A3:A5 and appends to A2. Lets say all my pdfs have 5 pages each. However what If I want to only take the first 3 A3, and full 5 pages of A4, and 1 page A5? Also I don't need to specify in between pages, ie 2 , 4 and 5 of A3. It will always be in order, ie 1-3 or 1-5 or 1-2. I have a counter that gets the number of pages already Dim i As Long, pgnumber As Range For Each pgnumber In Range(

Insert bold text into Word using VBA

早过忘川 提交于 2020-01-02 04:43:05
问题 I wrote a little script that exports certain Excel cell values into Word. However, certain inserts need to be bold. And there doesn't seem to be an easy way to do this. This code loops through the records and adds them to the Word document Do While intRow < intTotalRows + 1 strTemp = " ;b;" & Range("G" & intRow).FormulaR1C1 & " " & Range("I" & intRow).FormulaR1C1 & ";e; " If strTemp <> strCur Then strCur = strTemp .Content.Font.Bold = True .Content.InsertAfter strCur End If .Content.Font.Bold