So I have read online in many different places that I should not use .activate or commands like it. problem is my program HEAVILY relies on them.
Let me give some background first. I am writing a program to automate a part of my job. I have already written this particular portion of code months ago, and it worked perfectly well. However now that I am trying to update the code things that use to work are causing errors. namely the instances of ActiveCell.PasteSpecial. I read that it is the .activate that is causing the problem. Why is this only causing a problem now?
As for the main question I need my code to do 4 things
- get a account number from a specific cell.
- activate "sheet2" paste text date copied from a outside Program to "A1" and collect text data from different cells on "sheet2" based on the pasted data.
- activate "sheet1" paste data collected and receive the next account number.
- Switch between Excel and another program that only accepts keyboard entry. While this step is annoying it is not the step I need help on.
Here is the code I have so far. I know how to do most of the steps I am just lost when trying to get it done without .activate.
Sub Macro1() ' ' Macro1 Macro ' ' 'find missing emails Dim e As Range, Rang As Range Set Rang = Range("A2:A100") AppActivate "Microsoft Excel" Worksheets("Email_List").Activate Range("A1").Activate For Each e In Rang If Not IsEmpty(e.Value) = True Then ActiveCell.Offset(1, 0).Activate Sleep 700 ActiveCell.Offset(0, 3).Activate Sleep 700 If IsEmpty(ActiveCell.Value) Then ActiveCell.Offset(0, -3).Activate Sleep 700 ActiveCell.Copy Sleep 700 AppActivate "Other Program" Sleep 500 SendKeys "~", True Sleep 700 SendKeys "~", True Sleep 700 SendKeys "~", True Sleep 700 SendKeys "~", True Sleep 700 SendKeys "~", True Sleep 700 SendKeys "~", True Sleep 700 SendKeys "~", True Sleep 700 SendKeys "1", True Sleep 700 SendKeys "~", True Sleep 700 SendKeys "2", True Sleep 700 SendKeys "~", True Sleep 700 SendKeys "1", True Sleep 700 SendKeys "~", True Sleep 700 SendKeys "c ", True Sleep 700 SendKeys "^v", True Sleep 7001 SendKeys "^x", True Sleep 7000 SendKeys "^a", True Sleep 7000 SendKeys "^c", True Sleep 7000 AppActivate "Microsoft Excel" Sleep 500 Worksheets("Data").Activate Cells.Activate Cells.Delete Range("A1").Activate ActiveCell.PasteSpecial Sleep 500 If Range("A24").Value = "CONF# NOT FOUND, PRESS <ENTER>" Then Sleep 700 AppActivate "Other Program" Sleep 500 SendKeys "~", True Sleep 700 AppActivate "Microsoft Excel" Sleep 500 Worksheets("Email_List").Activate ElseIf Range("A24").Value = "ENTER RESERVATION NUMBER:" Then Range("D24").Activate ActiveCell.Value = "=LEFT(A6,6)" ActiveCell.Copy AppActivate "Other Program" Sleep 500 SendKeys "^v", True Sleep 700 SendKeys "30", True Sleep 700 SendKeys "~", True Sleep 700 SendKeys "^x", True Sleep 700 SendKeys "^a", True Sleep 700 SendKeys "^c", True Sleep 700 AppActivate "Microsoft Excel" Sleep 500 Worksheets("Data").Activate Cells.Activate Cells.Delete Range("A1").Activate ActiveCell.PasteSpecial Sleep 500 If Range("A8").Value = "3. E-FOLIO" Then Sleep 700 AppActivate "Other Program" Sleep 500 SendKeys ("3") Sleep 700 SendKeys ("~") Sleep 700 SendKeys "^x", True Sleep 700 SendKeys "^a", True Sleep 700 SendKeys "^c", True Sleep 700 AppActivate "Microsoft Excel" Sleep 500 Worksheets("Data").Activate Cells.Activate Cells.Delete Range("A1").Activate ActiveCell.PasteSpecial Sleep 700 Range("A21").Copy Worksheets("Email_List").Activate ActiveCell.Offset(0, 3).Activate ActiveCell.PasteSpecial ActiveCell.Offset(0, -3).Activate End If ElseIf Range("A2").Value = "===============================================================================" Then AppActivate "Other Program" Sleep 500 SendKeys "30", True Sleep 700 SendKeys "~", True Sleep 700 SendKeys "^x", True Sleep 700 SendKeys "^a", True Sleep 700 SendKeys "^c", True Sleep 700 AppActivate "Microsoft Excel" Sleep 500 Worksheets("Data").Activate Cells.Activate Cells.Delete Range("A1").Activate ActiveCell.PasteSpecial Sleep 500 If Range("A8").Value = "3. E-FOLIO" Then Sleep 700 AppActivate "Other Program" Sleep 500 SendKeys ("3") Sleep 700 SendKeys ("~") Sleep 700 SendKeys "^x", True Sleep 700 SendKeys "^a", True Sleep 700 SendKeys "^c", True Sleep 700 AppActivate "Microsoft Excel" Sleep 500 Worksheets("Data").Activate Cells.Activate Cells.Delete Range("A1").Activate ActiveCell.PasteSpecial Sleep 500 Range("A21").Copy Worksheets("Email_List").Activate ActiveCell.Offset(0, 3).Activate ActiveCell.PasteSpecial ActiveCell.Offset(0, -3).Activate End If End If Else ActiveCell.Offset(0, -3).Activate End If End If Next e End Sub Any help you can provide will be greatly appreciated.