excel-vba

Save attachment to hard drive

…衆ロ難τιáo~ 提交于 2020-01-06 08:22:23
问题 I am trying to code a simple task: retrieving an attachment from Access (2013) database and saving it to disk. At the moment I would like the code to get a first record from recordset and save the attachment to C:\maptest.pdf It shows error 3265: Item not found in this collection (yet every record in the database has an attachment). Does anyone have an idea what I am doing wrong? Private Sub CommandButton4_Click() Dim appAcc As New Access.Application Dim rst As DAO.Recordset2 Dim rsA As DAO

Obtain “sender” and “emailbody” properties

荒凉一梦 提交于 2020-01-06 08:21:08
问题 Background I scan the inbox in Outlook and report the results to a Excel spreadsheet based on the Title of the email. I will use the same example as in Microsoft office keyword and will say "Office". IE: Office: Problem with Laptop. I need to get the user name or email address that sent the mail and probably some keywords in the body of the email itself. I found the way to iterate through the items that have this keyword only by using tables and rows. Problem I have not been able to find a

Take data from all books to some table

我是研究僧i 提交于 2020-01-06 08:07:17
问题 I am very new in EXCEL (especially in VBA). I try to write logic that: go to all open books, if some book has sheet with name "Test", it should take data from named range "Table" and then append it to the Table1 from sheet ALLDATA in book ALLDATABOOK. I try to write this, can someone help me? Here is my code: Private Sub CommandButton1_Click() Dim book As Object Dim lst As ListObject Dim iList As Worksheet For Each book In Workbooks For Each iList In book.Sheets If iList.Name = "Test" Then

Error with IF/OR in VBA

*爱你&永不变心* 提交于 2020-01-06 08:04:19
问题 .Range("BS2:BS" & NewLastRow).Formula = "=IF((OR(BR2=""FLAG"",BO2>0)),""FLAG"",""NOFLAG"" ))" I am using this formula in VBA but it is not working. Syntax looks fine. 回答1: Too many ")" .Range("BS2:BS" & NewLastRow).Formula = "=IF(OR(BR2=""FLAG"",BO2>0),""FLAG"",""NOFLAG"" )" 回答2: In general, try the following: Make a workable formula in Excel Then select the cell with the workable formula Run the following code Public Sub PrintMeUsefulFormula() Dim strFormula As String Dim strParenth As

Trying to create a search/copy/paste VBA code

痞子三分冷 提交于 2020-01-06 08:00:39
问题 I am new to VBA and I'm trying to automate a reporting function on a spreadsheet which requires manual work that could be avoided. I have created the below code but I keep on receiving error messages. I will explain what I am trying to achieve and hopefully we will find a solution to this issue. I have two sheets, and I want to look into column L of Sheet1 and for all cells that has "NO" for value, I want to copy the value in column A of the same row, and paste it in the last row of Sheet2 in

Repeating macro code

拟墨画扇 提交于 2020-01-06 07:59:32
问题 I recorded this macro: Sheets("Sheet1").Select Range("D4:E4").Select Application.CutCopyMode = False Selection.Copy Sheets("ALB3").Select Range("C1").Select ActiveSheet.Paste I want to make a loop to repeat the process. From range D4:E4 to D200:E200 when do select To paste that on respective sheet name from ALB3 to ALB196. My data in sheet 1. Column a is sheets name, column d4 and e4, is the data that I want to paste on every sheet already created. 回答1: If you're trying to copy a range from

How to create a Pivot table when fields are on horizontal and vertical axes

跟風遠走 提交于 2020-01-06 07:59:28
问题 I am using a table that I need to convert in a pivot table However I have some fields from the pivot table are in the columns and some others are in the rows (Dates). which returns then the following pivot table: Is there a way to let the Pivot table read it? (I m also open for VBA Ideas to start) 回答1: Your data is currently "Crosstabulated" aka in a crosstab, which Pivots can't handle. You need to "Unpivot" your data using either PowerQuery or VBA. Use PowerQuery aka "Get and Transform" if

Trying to create a search/copy/paste VBA code

偶尔善良 提交于 2020-01-06 07:59:05
问题 I am new to VBA and I'm trying to automate a reporting function on a spreadsheet which requires manual work that could be avoided. I have created the below code but I keep on receiving error messages. I will explain what I am trying to achieve and hopefully we will find a solution to this issue. I have two sheets, and I want to look into column L of Sheet1 and for all cells that has "NO" for value, I want to copy the value in column A of the same row, and paste it in the last row of Sheet2 in

Excel not responding after running macro

谁说胖子不能爱 提交于 2020-01-06 07:54:30
问题 I used the below code to copy a column from one sheet to another and then replace the blank cells with a Null value: 'Copying If Employee sourceSheet.Activate Range(Cells(2, 7), Cells(Rows.Count, 7).End(xlUp)).Select Selection.Copy destSheet.Activate Range("E2", Cells(Rows.Count, 7)).PasteSpecial For Each cell In Range("E2", Cells(Rows.Count, 5)) If Len(cell.Value) = 0 Then cell.Value = "No" End If When I replace the for statement with Range("E2", Cells(500,5)) it is working fine. What might

Counting coloured cells doesn't work with conditional formatting in Excel

穿精又带淫゛_ 提交于 2020-01-06 07:46:06
问题 Trying to count the number of certain coloured cells on my worksheet using this peice of VBA code : Function CountRed(MyRange) CountRed = 0 For Each Cell In MyRange If Cell.Interior.Color = RGB(255, 0, 0) Then CountRed = CountRed + 1 End If Next Cell End Function Basically, counts the number of red cells. Now this works fine if I colour them myself but if i put conditional formatting in my worksheet to colour these cells it doesnt work. Here is my condition : =AND(NOT(ISBLANK(A3)),ISBLANK(D3)