Send keys break my macro

Mepwnz2010

New Member
Joined
Aug 20, 2014
Messages
9
I'm trying to automate a webpage for work and I've created the entire macro and ran it for about 2 weeks. However there are 2 fields (textboxes) in the website I cant figure out. It almost looks like they created another program and put it in the webpage. Like a notepad or something. Thus far I haven't cared cause I don't use them, but I want others to be able to use my macro too so I decided an easy fix would be to use sendkeys to tab down enter the information. Sure enough it works but for some reason when I add the sendkeys everything after them doesn't work anymore. I'm hoping there is some easy explanation as I don't want to rewrite the entire macro. Any help would be awesome. Note I have taken the sendkeys out of this text I'm pasting so that I can run the macro in the mean time.

Code:
Function GetIeByTitle(Title, Optional IsLike As Boolean, Optional IsFocus As Boolean) As Object  Dim w As Object
  For Each w In CreateObject("Shell.Application").Windows
    With w
      If .Name = "Windows Internet Explorer" Then
        If IsLike Then
          If InStr(1, .LocationName, Title, vbTextCompare) > 0 Then
            ' Partial title of window is found - activate IE window
            If IsFocus Then
              w.Visible = False
              w.Visible = True
            End If
            Set GetIeByTitle = w
            Exit For
          End If
        Else
          If StrComp(.LocationName & " - " & .Name, Title, 1) = 0 Then
            ' Title of window is found - activate IE window
            If IsFocus Then
              w.Visible = False
              w.Visible = True
            End If
            Set GetIeByTitle = w
            Exit For
          End If
        End If
      End If
    End With
  Next
  Set w = Nothing
 
      
End Function
                         '---------everything above here sets up rules for the macro---------------------


Sub CreateSFcase()
If IsEmpty(Range("a1")) Then
   MsgBox "No. of Bookings is blank" & """", 48
   Stop
End If


If IsEmpty(Range("a2")) Then
   MsgBox "Dispute Amount is blank" & """", 48
   Stop
End If


If IsEmpty(Range("a3")) Then
   MsgBox "Transaction Post Date is blank" & """", 48
   Stop
End If


If IsEmpty(Range("a4")) Then
   MsgBox "Accounting Assigned To is blank" & """", 48
Stop
End If


'If IsEmpty(Range("z2")) Then
   'MsgBox "Contact/Account Lookup Results is blank" & """", 48
   'Stop
'End If


'If IsEmpty(Range("a6")) Then
   'MsgBox "Contact/Account Lookup Results is blank" & """", 48
   'Stop
'End If


If IsEmpty(Range("a7")) Then
   MsgBox "Additional To is blank" & """", 48
   Stop
End If


If IsEmpty(Range("c12")) Then
   MsgBox "Subject is blank" & """", 48
   Stop
End If


If IsEmpty(Range("z1")) Then
   MsgBox "Description is blank" & """", 48
   Stop
End If


If IsEmpty(Range("z12")) Then
   MsgBox "Rich Text is blank" & """", 48
   Stop
End If


'-------------------------------------Everything from to the above green line checks to make sure macro is completely filled out before running the marco---------------------------------------------------------




  Dim ie As Object
  Dim Title As String
  Title = "New Case: Select Case Record Type ~ Salesforce.com - Unlimited Edition"
  Set ie = GetIeByTitle(Title, True, True)
  If ie Is Nothing Then
    MsgBox "Please open the correct Salesforce window" & vbLf & """" & Title & """", 48
    Stop
     End If
'---------------------------------this pulls up SF---------------------------------------------
 With ie
      ie.document.getElementsByName("save").Item(1).Click
 End With
 
 '------------------------------------------------------Clicks continue to start creating the case------------------------------------------------------------------------------------------------
         
         Do
         DoEvents
         Loop Until ie.readyState = 3
         
         Do
         DoEvents
         Loop Until ie.readyState = 4
  
         
 With ie
      ie.document.all("00NC0000004ytz0").Value = ThisWorkbook.Sheets("sheet1").Range("a1")    'No. of Bookings
      ie.document.all("00NC0000004ytyr").Value = ThisWorkbook.Sheets("sheet1").Range("a2")    'Dispute Amount
      ie.document.all("00NC0000004zYJh").Value = ThisWorkbook.Sheets("sheet1").Range("a3")    'Transaction Post Date
      ie.document.all("CF00NC0000004ytyj").Value = ThisWorkbook.Sheets("sheet1").Range("a4")  'Accounting assigned to
      ie.document.all("cas14").Value = ThisWorkbook.Sheets("sheet1").Range("c12")             'Subject
      ie.document.all("cas15").Value = ThisWorkbook.Sheets("sheet1").Range("z1")              'Description
 End With
 
'------------------------------------------------------------Fills in all the text boxes----------------------------------------------------------------------------------------------------------
  
  With ie
      ie.document.all("00NC0000004yKpj").Value = ThisWorkbook.Sheets("sheet1").Range("z3")   'Team
      ie.document.all("00NC0000005ZDOq").Value = ThisWorkbook.Sheets("sheet1").Range("z4")   'Location
      ie.document.all("cas11").Value = ThisWorkbook.Sheets("sheet1").Range("z5")             'Case Origin
      ie.document.all("cas5").Value = ThisWorkbook.Sheets("sheet1").Range("z6")              'Type
      'ie.document.all("00NC0000004yBn3").Value = ThisWorkbook.Sheets("sheet1").Range("x")   'Case Category 1
      ie.document.all("cas7").Value = ThisWorkbook.Sheets("sheet1").Range("z7")              'Status
      ie.document.all("00NC0000004ytz9").Value = ThisWorkbook.Sheets("sheet1").Range("z8")   'Resolution Type
      ie.document.all("00NC0000004ytz2").Value = ThisWorkbook.Sheets("sheet1").Range("z9")   'Operational Unit
 End With
'-----------------------------------------------------------------Do all the drop down boxes------------------------------------------------------------------------------------------------------


 With ie
      ie.document.getElementsByName("save").Item(1).Click
 End With
 
 '-----------------------------------------------------------------Pushs save to create the case--------------------------------------------------------------------------------------------------
 
         Do
         DoEvents
         Loop Until ie.readyState = 3


         Do
         DoEvents
         Loop Until ie.readyState = 4
         
 With ie
      ie.document.getElementsByName("edit").Item(1).Click
 End With
         
'---------------------------------------------------------Click edit to put in the case look up contacts------------------------------------------------------------------------------------------


         Do
         DoEvents
         Loop Until ie.readyState = 3


         Do
         DoEvents
         Loop Until ie.readyState = 4
         
  With ie
       ie.document.all("00NC0000004yBn3").Value = ThisWorkbook.Sheets("sheet1").Range("z10")  'Case Category 2
       'ie.document.all("00nc0000004y1ygMAA").Value = ThisWorkbook.Sheets("sheet1").Range("z2") 'Case contact look up info
       'ie.document.getElementsByName("save").Item(1).Click
  End With
  
  'With ie
       'Application.Wait Now + TimeValue("00:00:01")
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
              'Range("z2").Select
              'Selection.Copy
       'Set ie = GetIeByTitle(Title, True, True)
          'Application.Wait Now + TimeValue("00:00:01")
          'Call SendKeys("^v", True)
          'Application.Wait Now + TimeValue("00:00:01")
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
       'Set ie = GetIeByTitle(Title, True, True)
          'Call SendKeys("{TAB}", True)
              'Range("z12").Select
              'Selection.Copy
       'Set ie = GetIeByTitle(Title, True, True)
          'Application.Wait Now + TimeValue("00:00:01")
          'Call SendKeys("^v", True)
          'Application.Wait Now + TimeValue("00:00:01")
  'End With


  With ie
        ie.document.getElementsByName("save").Item(0).Click
  End With
  
'------------------------------------------------Finishes Case Category and Case Contact Look Up Information---------------------------------------------------------------------------------------


         Do
         DoEvents
         Loop Until ie.readyState = 3


         Do
         DoEvents
         Loop Until ie.readyState = 4
         
  With ie
       ie.document.getElementsByName("newComment").Item(0).Click            'clicks new comment
  End With
  
         Do
         DoEvents
         Loop Until ie.readyState = 3


         Do
         DoEvents
         Loop Until ie.readyState = 4
         
  With ie
       ie.document.all("CommentBody").Value = ThisWorkbook.Sheets("sheet1").Range("z11") 'Case comment
       ie.document.getElementsByName("save").Item(1).Click             'clicks save case comment
  End With
  
'----------------------------------------------------------------This does the case comment-------------------------------------------------------------------------------------------------------
  
         Do
         DoEvents
         Loop Until ie.readyState = 3


         Do
         DoEvents
         Loop Until ie.readyState = 4
         
  With ie
       ie.document.getElementsByName("newEmail").Item(0).Click            'clicks send email
  End With
         Do
         DoEvents
         Loop Until ie.readyState = 3
         Do
         DoEvents
         Loop Until ie.readyState = 4
  With ie
       ie.document.all("p24").Value = ThisWorkbook.Sheets("sheet1").Range("a7")  'puts in Additional To: contects
                 newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 1
waitTime = TimeSerial(newHour, newMinute, newSecond)
Application.Wait waitTime
       ie.document.getElementsByName("template").Item(1).Click
  End With




  
  
  
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top