NessPJ
Active Member
- Joined
- May 10, 2011
- Messages
- 431
- Office Version
- 365
Hi,
I'm trying to make a simple sheet that can send a line of text to a Discord chat window.
The line: GetObject("", "" & strPartialTitle & "")
does not seem to be working though.
The Window name in windows contains the text " #general " but when i use this as 'strPartialTitle' it does not want to work.
Am i doing something wrong here?
I'm trying to make a simple sheet that can send a line of text to a Discord chat window.
The line: GetObject("", "" & strPartialTitle & "")
does not seem to be working though.
The Window name in windows contains the text " #general " but when i use this as 'strPartialTitle' it does not want to work.
Am i doing something wrong here?
VBA Code:
Sub SendMessageToWindow()
'Declare variables
Dim objWindow As Object
Dim strText As String
Dim strPartialTitle As String
Dim lngRow As Long
Dim dblWaitTime As Double
'Get the partial title of the window from Sheet2 cell A2
strPartialTitle = Sheets("Sheet2").Range("A2").Value
'Get the wait time from Sheet2 cell A3
dblWaitTime = Sheets("Sheet2").Range("A3").Value
'Get the window object
On Error Resume Next
Set objWindow = GetObject("", "" & strPartialTitle & "")
On Error GoTo 0
'Check if the window was found
If objWindow Is Nothing Then
MsgBox "Window with title containing '" & strPartialTitle & "' was not found."
Exit Sub
End If
'Initialize the row counter
lngRow = 1
'Send the messages in the list indefinitely
Do
Do While Not IsEmpty(Sheets("Sheet1").Range("A" & lngRow))
strText = "/imagine " & Sheets("Sheet1").Range("A" & lngRow).Value
objWindow.SendKeys strText & "{ENTER}"
lngRow = lngRow + 1
Loop
lngRow = 1
Application.Wait (Now + TimeValue(dblWaitTime))
Loop
End Sub
Sub StopExecution()
'Stop the execution of the current routine
Stop
End Sub