简体   繁体   中英

How can I use VBA to fill in a JavaScript textarea?

I'm looking at the following JavaScript code:

<tr><td><textarea name="dump" rows="15" cols="80" maxlength="32768"></textarea></td></tr>

I need to fill this text area with a number of strings seperated by semicolons. I'm not sure if I've succeded, but also I'm not sure how I can update the website with the new HTML document.

Here's what I wrote:

Dim siteText As String

siteText = IE.document.DocumentElement.innerHTML
siteText = InsertServer(siteText, "string") 'Where the character count is right before "</textarea>

Here's my function:

Function InsertServer(ByVal site As String, text As String) As String

InsertServer = Left(site, 9095) & text + ";" & Right(site, 9095 + Len(text))

End Function

EDIT

Since it seems to be a problem with the function call, I tried transforming it into a subroutine:

siteText = IE.document.DocumentElement.innerHTML
InsertServer

Sub InsertServer()
siteText = Left(site, 9095) & "text" & ";" & Right(site, 9095 & Len(server))
End Sub

I also tried:

siteText = IE.document.DocumentElement.innerHTML
insert = InsertServer(siteText, "text")

Sub InsertServer(site As String, text As String)
siteText = Left(site, 9095) & text & ";" & Right(site, 9095 & Len(server)) 
End Sub

Neither worked. I've only been work with VBA for a few weeks, so I'm really not sure what approach to take...

Try the below. By the looks of it you're not concatenating strings correctly. You need to use & rather than + . Also, Right(site, 9095 & Len(server)) should be a calculation rather + as below.

Function InsertServer(ByVal site As String, text As String) As String

InsertServer = Left(site, 9095) & text & ";" & Right(site, 9095 + Len(server))

End Function

Edit

Where you call the function, you've included an additional parameter which isn't needed according to the function:

siteText = InsertServer(siteText, "string", 9095) 'Where the character count is right before "</textarea>

Should be:

siteText = InsertServer(siteText, "string") 'Where the character count is right before "</textarea>

If there's no error being thrown when the code is executed, it indicates that the function is not being called at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM