vba

Excel VBA - Using Arrays to find and replace strings

时间秒杀一切 提交于 2021-02-05 09:36:00
问题 I am using arrays to find certain strings and replace them with an more standard value: Dim Keywords As Variant Dim MachineNames As Variant Keywords = Array("SAM ", "Press ", "Robot", "Robot 1", "Robot 2", "Robot 3", "Robot 4", "Robot 5", "Robot 6", "FA ", "FA 1", "FA1", "FA 2", "FA2", "FA 3", "FA3", "FA 4", "FA4", "FA 5", "FA5", "FA 6", "FA6", "FA 7", "FA7", "FA 8", "FA8", "FA 9", "FA9", "FA 10", "FA10", "FA 11", "FA11", "FA 12", "FA12", "St 120", "St 95", "St 90C", "Flex Arc", "Flex Arch",

Using a variable in a range statement in VBA excell macro

陌路散爱 提交于 2021-02-05 09:32:28
问题 Ok, I'm sure this question is really basic but all my searchers turn up complicated answers and I've been messing with VBA for about a day. I have two worksheets in an excel doc, I've created a button that I can click that invokes my macro that is just moving cells from one work sheet to another. But I need my macro to determine what row I am on. I'm using this: r = ActiveCell.Row to determine my row, but what would be the easiest way to use that variable in a range statement like this: Range

Using a variable in a range statement in VBA excell macro

拟墨画扇 提交于 2021-02-05 09:32:12
问题 Ok, I'm sure this question is really basic but all my searchers turn up complicated answers and I've been messing with VBA for about a day. I have two worksheets in an excel doc, I've created a button that I can click that invokes my macro that is just moving cells from one work sheet to another. But I need my macro to determine what row I am on. I'm using this: r = ActiveCell.Row to determine my row, but what would be the easiest way to use that variable in a range statement like this: Range

Error saving attachments when they are embedded

非 Y 不嫁゛ 提交于 2021-02-05 09:27:13
问题 I'm saving Outlook attachments (as part of a copy). I get an error message from the line objAtt.SaveAsFile strFile when the attachment is an embedded image. The code (gratefully copied!) is: Sub CopyAttachments(objSourceItem, objTargetItem) Dim objAtt As Outlook.Attachment Set fso = CreateObject("Scripting.FileSystemObject") Set fldTemp = fso.GetSpecialFolder(2) ' TemporaryFolder strPath = fldTemp.Path & "\" For Each objAtt In objSourceItem.Attachments strFile = strPath & objAtt.FileName

VBA editing cells in protected sheet

自古美人都是妖i 提交于 2021-02-05 09:24:26
问题 I have protected a workbook using vba code. I would also like to let the user entering some values in the specific cells (n4, p7:p10) . I have tried by using the following code but it doesn't work. A pop-up error message mentions "Error 1004" . Range ("n4,p7:p10").select Selection.locked=false 回答1: Const wsPass As String = "Password123" '//Change to your password For Each ws In ThisWorkbook.Sheets ws.Unprotect wsPass ws.Range("N4, P7:P10").Cells.Locked = False ws.Protect wsPass Next ws Just a

VBA editing cells in protected sheet

核能气质少年 提交于 2021-02-05 09:23:55
问题 I have protected a workbook using vba code. I would also like to let the user entering some values in the specific cells (n4, p7:p10) . I have tried by using the following code but it doesn't work. A pop-up error message mentions "Error 1004" . Range ("n4,p7:p10").select Selection.locked=false 回答1: Const wsPass As String = "Password123" '//Change to your password For Each ws In ThisWorkbook.Sheets ws.Unprotect wsPass ws.Range("N4, P7:P10").Cells.Locked = False ws.Protect wsPass Next ws Just a

How to add sequential numbers next to data from query

不问归期 提交于 2021-02-05 09:23:44
问题 I have a table named tblFriends : tblFriends is generated from query qryFriends . The data and number of records within tblFriends changes everyday but is never more than 30. I would like to generate sequential numbers next to each of the Names, but this seems to be extremely difficult. I have tried looping insert queries as shown below: strSQLaddSEQ = "ALTER TABLE tblFriends ADD SEQ Number;" DoCmd.RunSQL strSQLaddSEQ For SEQNum = 1 To 30 strSqlSEQNum = "INSERT INTO Friends (SEQ) Values(" &

Object variable with or with block not set

家住魔仙堡 提交于 2021-02-05 09:01:31
问题 I have xml file which I am trying to parse: This is the xml file content <MYSTUFF> <COMPANYNAMES> <COMPANYNAME>JUMPIN (JIMMY) LIMITED</COMPANYNAME> <COMPANYNAME>BLADE RUNNER'S TRANSPORT</COMPANYNAME> <COMPANYNAME>P Griffiths & Sons</COMPANYNAME> <COMPANYNAME>SOMETIMES, NEVER</COMPANYNAME> <COMPANYNAME>MASTER/CLASS</COMPANYNAME> </COMPANYNAMES> <FIRSTNAMES> <FIRSTNAME>Richard</FIRSTNAME> <FIRSTNAME>Jo & hn</FIRSTNAME> <FIRSTNAME>Paul</FIRSTNAME> <FIRSTNAME>Geo, rge</FIRSTNAME> <FIRSTNAME>Ringo

Have more than one Worksheet_Change in a Worksheet

别等时光非礼了梦想. 提交于 2021-02-05 08:58:48
问题 I am looking to limit my workbook users to 1000 characters over a range of cells (Example: A5:A30) . In other words limit the total characters in the range A5:A30 to 1000 characters. When a user fills in a cell that sends the range over the 1000 character limit, it will call Application.undo which should just remove the last text that they added. However since I have another Private Sub Worksheet_Change(ByVal Targe As Range) on the worksheet, it causes a bug. Below is both Worksheet_Change

Looping through excel worksheets, in mulitple workbooks in the same directory while copying data into a new workbook

倾然丶 夕夏残阳落幕 提交于 2021-02-05 08:57:18
问题 So I have been working for a couple hours on how to get this existing code to function the way I want it to. This code by itself would loop through workbooks in a directory and copy data from specific cells on the first sheet to a new workbook. I would like to have it do that, but also go through each worksheet in each workbook to get the required data. I would post all the versions of my data that I have tried but, I'm sure that will get me banned as well. So I will post my most recent: Sub