Stuck with problem - looking for help

A

alexm999

I am trying to add phone numbers into a websheet. With the code below, I
can only add 1 number at a time and the very 1st number on my list.
I'd like to add ALL the numbers in row A. Also, when it adds 1 number,
it adds funky numbers to the back, for example if the number was
12125551212 - it would look like 121255512121123400000
Any ideas? Heres the code: I blocked out my user name and password for
safety! :)

Private Declare Function GetIpAddrTable_API Lib "IpHlpApi" Alias
"GetIpAddrTable" (pIPAddrTable As Any, pdwSize As Long, ByVal bOrder As
Long) As Long

Private Function GetIpAddress()
Dim result As Long, Buf(511) As Byte, BufSize As Long

result = GetIpAddrTable_API(Buf(0), UBound(Buf) + 1, 1)

If result <> 0 Then
GetIpAddress = "127.0.0.1"
Else
For i = 0 To (Buf(1) * 256 + Buf(0) - 1)
IpAddress = ""
For j = 0 To 3
IpAddress = IpAddress & IIf(j > 0, ".", "") & Buf(4 + i
* 24 + j)
Next

If IpAddress <> "" Then
GetIpAddress = IpAddress
Exit Function
End If
Next i
End If
End Function


Private Function CreateFormData(ByRef Fields As Variant, ByVal
FormDataDelimiter As String, ParamArray Values() As Variant)

Dim FormData As String
FormData = FormDataDelimiter & vbCrLf

For i = 0 To UBound(Fields)
FormData = FormData & "Content-Disposition: form-data; name="""
& Fields(i) & """" & vbCrLf & vbCrLf & Values(i) & vbCrLf &
FormDataDelimiter & vbCrLf
Next i

CreateFormData = FormData
End Function


'
Public Sub UploadExcludeList()


Dim FormDataDelimiter As String
FormDataDelimiter = "---------------------------7d619d2ff0292"

Dim FormDataFile As String
FormDataFile = "C:\Documents and Settings\Alex
Markovich\Desktop\removeme1.csv"

Dim WebRoot As String
WebRoot = "https://www.protusfax.com/protus/"

Dim UserID As String
UserID = "888888"

Dim UserPassword As String
UserPassword = "password"

Dim UserIP As String
UserIP = GetIpAddress

'
############################################################################################################

Dim wHTTPReq As New WinHttpRequest
Dim StartTime As Date

wHTTPReq.Option(WinHttpRequestOption_UserAgentString) =
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
1.1.4322; .NET CLR 2.0.50727)"
wHTTPReq.Open "GET", WebRoot & "/general/FindAccounts.asp", False
wHTTPReq.Send

If wHTTPReq.Status <> 200 Then
Debug.Print "Session Could Not Be Created."
Exit Sub
End If

StartTime = Now()
wHTTPReq.Open "POST", WebRoot & "/general/FindAccounts.asp?",
False
wHTTPReq.SetRequestHeader "Referer", WebRoot &
"/general/FindAccounts.asp"
wHTTPReq.SetRequestHeader "Content-Type",
"application/x-www-form-urlencoded"
wHTTPReq.SetRequestHeader "Cookie", "WT_FPC=id=" & UserIP & "-" &
"1619067696" & ":lv=" & (DateDiff("s", #1/1/1970#, StartTime) * 1000) &
":ss=" & (DateDiff("s", #1/1/1970#, Now()) * 1000)
wHTTPReq.Send "rt=&mpid=&bid=&cboFind=1&vfax=" & UserID & "&pw=" &
UserPassword & "&Submit=Login"

If wHTTPReq.Status <> 200 Then
Debug.Print "Login Unsuccessful."
Exit Sub
End If

wHTTPReq.Open "POST", WebRoot & "/contacts/listadmin.asp?u=1",
False
wHTTPReq.SetRequestHeader "Referer", WebRoot &
"/contacts/listadmin.asp"
wHTTPReq.SetRequestHeader "Content-Type", "multipart/form-data;
boundary=" & FormDataDelimiter
wHTTPReq.SetRequestHeader "Cookie", "WT_FPC=id=" & UserIP & "-" &
"1619067696" & ":lv=" & (DateDiff("s", #1/1/1970#, StartTime) * 1000) &
":ss=" & (DateDiff("s", #1/1/1970#, Now()) * 1000)

Dim FormData As String
FormData = CreateFormData(Split("smode:di:pm:uloadexclude", ":"),
"--" & FormDataDelimiter, 2, "", 7, 1)
FormData = FormData & "Content-Disposition: form-data;
name=""usearch""; filename=""" & FormDataFile & """" & vbCrLf
FormData = FormData & "Content-Type: application/vnd.ms-excel" &
vbCrLf & vbCrLf
Open FormDataFile For Input Access Read As #1
While Not EOF(1)
Line Input #1, WholeLine
FormData = FormData & WholeLine
Wend
Close #1
FormData = FormData & vbCrLf & "--" & FormDataDelimiter & "--" &
vbCrLf
wHTTPReq.Send FormData

If wHTTPReq.Status = 500 Then
Debug.Print "File Was Uploaded Successfully."
End If
End Sub
 
N

NickHK

Alex,
This works for me:
http://www.source-code.biz/snippets/vbasic/8.htm

If you need more info from the function you can use the example in the the
API-Guide, http://www.allapi.net/: e.g.

Const MAX_IP = 5 'To make a buffer... i dont think you have more than 5 ip
on your pc..
Type IPINFO
dwAddr As Long ' IP address
dwIndex As Long ' interface index
dwMask As Long ' subnet mask
dwBCastAddr As Long ' broadcast address
dwReasmSize As Long ' assembly size
unused1 As Integer ' not currently used
unused2 As Integer '; not currently used
End Type
Type MIB_IPADDRTABLE
dEntrys As Long 'number of entries in the table
mIPInfo(MAX_IP) As IPINFO 'array of IP address entries
End Type
Type IP_Array
mBuffer As MIB_IPADDRTABLE
BufferLen As Long
End Type

NickHK
 
A

alexm999

I'm still getting an error when I post. I can only get cell A1 to post
not the whole row A:A. Any idea's?
Also, when it posts something, it for somereason adds wierd numbers a
the end of the phone number (ex 21255512128475654000)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top