Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-10-2016, 10:08 PM
PRA007's Avatar
PRA007 PRA007 is offline How to run vba asynchly Windows 7 64bit How to run vba asynchly Office 2010 32bit
Competent Performer
How to run vba asynchly
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default How to run vba asynchly

While I got nice answer at: https://www.msofficeforums.com/word-...data-word.html, I thought what is need of such complicated process?

After spending much time with VBA I realized that, if not proper, VBA may be wasting your time rather than saving.



This is example of time wasting VBA.

Code:
Sub DownPDFFromHLnk()
Application.ScreenUpdating = False
Dim StrTxt As String, HttpReq As Object
Set HttpReq = CreateObject("Microsoft.XMLHTTP")
With ActiveDocument.Range
    With .Find
        .ClearFormatting
        .Replacement.ClearFormatting
        .Text = "[A-Z]{2} [0-9,]{5,}"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchWildcards = True
        .Execute
    End With
        Do While .Find.Found
            If .Hyperlinks.Count > 0 Then
                f = ActiveDocument.Path & Application.PathSeparator & .Text & ".pdf"
                HttpReq.Open "GET", .Hyperlinks(1).Name, False
                HttpReq.send
                    If HttpReq.Status = 200 Then
                        Set oStream = CreateObject("ADODB.Stream")
                        oStream.Open
                        oStream.Type = 1
                        oStream.Write HttpReq.responseBody
                        oStream.SaveToFile f, 2
                        oStream.Close
                        .Hyperlinks(1).Address = f
                    End If
            End If
        .Collapse wdCollapseEnd
        .Find.Execute
        Loop
End With
End Sub
I want to convert the httpreq part into function.
I tried from the above mentioned post but could not figure it out. Please help me learn Use of VBA function.
Reply With Quote
 

Tags
vba



Other Forums: Access Forums

All times are GMT -7. The time now is 10:21 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft