VBA - Send Chat text to a Discord window?

NessPJ

Active Member
Joined
May 10, 2011
Messages
431
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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,224,826
Messages
6,181,192
Members
453,021
Latest member
pingpong7117

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