Pulling data from csv and place on worksheet without using clipboard?

DavMet

New Member
Joined
Jan 28, 2025
Messages
1
Office Version
  1. 2021
Platform
  1. Windows
Have a file for work that we need to try and be able to have automatically update even if the computer it is running on is locked which means we have to bypass the clipboard for pretty much everything. Most of the data sources are urls that generate a csv for us using variables we pass to it. The code I have works under normal use (ie unlocked computer) but I am unsure if it is possible to bypass the clipboard when pulling from a csv file.

Any help would be appreciated.


VBA Code:
Private FC As String
Private StartTime As Date, EndTime As Date
Private sheet As Worksheet
Private Dte As String
Option Explicit


Sub GetLPDensity()
        Dim H As XMLHTTP60
        Dim DataObj As New MSForms.DataObject
        Set PerfTrack = ThisWorkbook.Worksheets("Psheet")
        StartTime = starttime
        EndTime = endtime
        Dte = Format(date from cell, "YYYY-MM-DD")
        FC = ID of building

        Dim URL As String

        URL = "" 'link to pull csv from, not a directlink to csv file
        
Debug.Print URL
        launchLPD (URL)

End Sub


Sub launchLPD(ByRef URL As String)
Dim httpRequest As XMLHTTP60
Dim DataObj As New MSForms.DataObject

    Set httpRequest = New XMLHTTP60
        httpRequest.Open "GET", URL, False
        httpRequest.setRequestHeader "Content-Type", "application/x-w&ww-form-urlencoded"
        httpRequest.Send ""

    DataObj.SetText httpRequest.ResponseText
    DataObj.PutInClipboard

    With PasteRange
        .Activate
        .UsedRange.ClearContents
        .Cells(1, 1).Select
        .PasteSpecial Format:="Text", link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
        If .Range("A1") = "X" Then GoTo skipT2C
        .Range("A:A").Select
    End With

    Selection.TextToColumns Destination:=Range("A:A"), DataType:=xlDelimited, _
        Tab:=True, Semicolon:=False, comma:=True, Space:=False, Other:=False, OtherChar:="-"
   Exit Sub

skipT2C:

End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
You could also use Power Query to bring the csv file into PQ Editor, clean the file so only the data you want. (No coding as can be done in UI). Close and load your output to your existing Excel file.
 
Upvote 0

Forum statistics

Threads
1,226,017
Messages
6,188,441
Members
453,474
Latest member
th9r

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