VBA - Send Chat text to a Discord window?

NessPJ

Active Member
Joined
May 10, 2011
Messages
422
Office Version
  1. 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?

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
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Using stars as a wildcard for the Window name did not seem to help either.

VBA Code:
Set objWindow = GetObject("", "" & "*" & strPartialTitle & "*" & "")
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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