VBA code to automate logbook data import into excel

Post questions and issues with Concept2 PM3 SDK
Post Reply
Rfarkash
Paddler
Posts: 8
Joined: November 12th, 2024, 11:17 pm

VBA code to automate logbook data import into excel

Post by Rfarkash » January 28th, 2025, 11:23 pm

Sorry if this is the wrong forum - please move if needed.
Trying to figure out how to write a vba macro to automatically import logbook data into an excel spreadsheet for analysis. I requested and received a Logbook API key, but so far haven't been able to successfully import.
Full disclosure - know my way around excel and VBA, not a computer guy otherwise and API/JSON/GITHUB etc are just a bunch of letters to me right now lol.
Anybody have a simple macro to automate the import they would be willing to share, or pointers on where to start from scratch?
Thx
Ron

James_smith
Paddler
Posts: 1
Joined: March 19th, 2025, 12:27 pm

Re: VBA code to automate logbook data import into excel

Post by James_smith » March 19th, 2025, 12:28 pm

Here’s a VBA script to automate the import of logbook data into Excel from a CSV or text file. This script allows you to browse and select a file, then imports its content into a worksheet.

Steps to Use the VBA Code:
Open Excel and press ALT + F11 to open the VBA Editor.
Click Insert > Module.
Copy and paste the following VBA code.
Run the macro named ImportLogbookData().
VBA Code:
vba
Copy

Edit

Code: Select all

Sub ImportLogbookData()
    Dim ws As Worksheet
    Dim filePath As String
    Dim fileDialog As FileDialog
    Dim lastRow As Long
    
    ' Set the worksheet where data will be imported
    Set ws = ThisWorkbook.Sheets("LogbookData") ' Change to your sheet name
    
    ' Open File Dialog to Select Logbook File
    Set fileDialog = Application.FileDialog(msoFileDialogFilePicker)
    fileDialog.Title = "Select Logbook File"
    fileDialog.Filters.Clear
    fileDialog.Filters.Add "CSV Files", "*.csv;*.txt", 1
    
    If fileDialog.Show = -1 Then
        filePath = fileDialog.SelectedItems(1)
    Else
        MsgBox "No file selected. Import cancelled.", vbExclamation
        Exit Sub
    End If
    
    ' Clear old data before import
    ws.Cells.Clear
    
    ' Import data using QueryTables
    With ws.QueryTables.Add(Connection:="TEXT;" & filePath, Destination:=ws.Range("A1"))
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileCommaDelimiter = True
        .TextFilePlatform = xlWindows
        .Refresh
    End With
    
    MsgBox "Logbook data imported successfully!", vbInformation
End Sub
How This Works:
✅ Opens a file dialog to select the logbook file.
✅ Clears previous data before importing new data.
✅ Imports CSV or text-based logbook data into Sheet "LogbookData".
✅ Displays a message once the import is complete.

Let me know if you need modifications like date formatting, column selection, or specific delimiters!

louiseravot
Paddler
Posts: 3
Joined: July 14th, 2025, 7:11 am

Re: VBA code to automate logbook data import into excel

Post by louiseravot » July 15th, 2025, 1:24 pm

Start by using VBA’s XMLHTTP to call the API, then use a JSON parser like VBA-JSON to handle the data and import it into Excel. Check online for simple VBA JSON tutorials to help you get started.

User avatar
Citroen
SpamTeam
Posts: 8084
Joined: March 16th, 2006, 3:28 pm
Location: A small cave in deepest darkest Basingstoke, UK

Re: VBA code to automate logbook data import into excel

Post by Citroen » July 15th, 2025, 1:51 pm

If you're going to post code on here please use [code][/code] tags. They make your code more readable and easier to copy.

There's a [</>] icon when you create a posting that adds them automatically.

I've edited your posting, using my moderator powers.

louiseravot
Paddler
Posts: 3
Joined: July 14th, 2025, 7:11 am

Re: VBA code to automate logbook data import into excel

Post by louiseravot » July 19th, 2025, 7:36 pm

louiseravot wrote:
July 15th, 2025, 1:24 pm
Start by using VBA’s XMLHTTP to call the API, then use a JSON parser like VBA-JSON to handle the data and import it into Excel. Check online for simple VBA JSON tutorials to help you get started.
Start by using VBA’s XMLHTTP to call the API, then use a JSON parser like VBA-JSON to handle the data and import it into Excel. Check online for simple VBA JSON tutorials to help you get started. For location-based API access or delivery info, you can also explore this postcode tool.

Post Reply