+ Reply to Thread
Results 1 to 3 of 3

Online Excel Database

Hybrid View

  1. #1
    Registered User
    Join Date
    03-16-2014
    Location
    Bangalore
    MS-Off Ver
    Excel 2016
    Posts
    46

    Post Online Excel Database

    Im looking for a solution which i need to achieve using excel.
    Im creating a VBA application using excel.
    I need all the data on the excel sheet to be stored online in some table/database.
    This would enable me to use the same excel sheet on multiple systems at the same time and having up to date information on all the systems.
    Please let me know whether such a thing is possible.
    Also let me know the various options available.

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Online Excel Database

    You may consider saving the data as a CSV file to a shared drive. The following is code to read and write CSV Files. However, I recommend using MS-Query to read the data from the CSV file. It will bring it in as a table. Also it will preserve the data type. Sometimes when you import a big string that looks like a number, Excel converts it to scientific notation which is not what you generally want.

    Option Explicit
    
    ' Syntax: ReadCSV CSVPath, CSVFile, PasteSheet, PasteRange
    ' Syntax: WriteCSV CSVPath, CSVFile, CopySheet, CopyRange
    
    
    Sub ReadCSV(CSVPath As String, CSVFile As String, PasteSheet As String, PasteRange As String)
    Dim xlBook As Excel.Workbook, xlCSV As Excel.Workbook
    
    Set xlBook = ThisWorkbook
    
    Application.DisplayAlerts = False
    
    ' Clear the old data
    Sheets(PasteSheet).Cells.ClearContents
    
    ' Open the CSV File
    If Dir(CSVPath & "\" & CSVFile) = "" Then
        MsgBox "File " & CSVFile & " does not exist"
        Exit Sub
    End If
    
    Set xlCSV = Workbooks.Open(CSVPath & "\" & CSVFile)
    Cells.Copy
    
    ' Paste to CSV
    xlBook.Activate
    Sheets(PasteSheet).Select
    Range(PasteRange).Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    ' Close the book
    xlCSV.Close savechanges:=False
    Application.DisplayAlerts = True
    
    End Sub
    
    
    Sub WriteCSV(CSVPath as String, CSVFile as String, CopySheet as String, CopyRange as String)
    Dim xlCSV As Excel.Workbook, xlBook As Excel.Workbook
    
    Application.DisplayAlerts = False
    Set xlBook = ThisWorkbook
    Sheets(CopySheet).Select
    
    ' Create the CSV File
    Set xlCSV = Workbooks.Add(xlWBATWorksheet)
    
    ' Copy the data
    xlBook.ActiveSheet.Range(CopyRange).Copy _
        xlCSV.Sheets(1).Range("A1")
        
    ' Save and close the CSV File
    xlCSV.SaveAs Filename:=CSVPath & "\" & CSVFile, FileFormat:=xlCSVMSDOS
    xlCSV.Close savechanges:=True
    Application.DisplayAlerts = True
    
    End Sub

  3. #3
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,957

    Re: Online Excel Database

    I'll put in a plug for Excel files here. Excel files know how big they are so you always know what the copy range is.

    Here is a pointer to how to work with Excel files: http://www.excelforum.com/excel-prog...-database.html.

    Here is code on how to clear an Excel file. The syntax is ClearTable SheetName, TableName
    Option Explicit
    
    Sub ClearTable(TableSheet As String, TableName As String)
    
    If FilterIsOn(Sheets(TableSheet).ListObjects(TableName)) = True Then
        Range(TableName).AutoFilter
        Range(TableName).AutoFilter
    Else
        Range(TableName).AutoFilter
    End If
    
    If Range(TableName).Rows.Count > 2 Then
        Range(TableName).Delete
        Exit Sub
    End If
    
    If CountFields(Range(TableName & "[#Headers]").Offset(1, 0)) > 0 Then
        Range(TableName).Delete
    End If
    
    End Sub
    
    Function CountFields(MyRange As Range) As Long
    Dim cl As Range
    Dim Counter As Long
    
    On Error Resume Next
    Counter = 0
    For Each cl In MyRange
        If Len(cl.Value) > 0 Then
            Counter = Counter + 1
        End If
    Next
    
    CountFields = Counter
    
    End Function
    
    Function FilterIsOn(lo As ListObject) As Boolean
     
    Dim bOn As Boolean
     
    bOn = False
     On Error Resume Next
     If lo.AutoFilter.Filters.Count > 0 Then
         If Err.Number = 0 Then bOn = True
     End If
     On Error GoTo 0
     FilterIsOn = bOn
     End Function

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Querying Online Database With Excel VBA
    By NeedForExcel in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 09-30-2015, 11:01 PM
  2. Online database for Excel data dump
    By gregersdk in forum Excel General
    Replies: 6
    Last Post: 11-27-2014, 12:08 PM
  3. how to get data from online database??
    By mahaveersomani in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-03-2014, 09:52 AM
  4. Excel data live to online Database
    By promoboy2 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-22-2013, 06:02 AM
  5. Is it possible to import data to excel from an access database online?
    By Rob* in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-16-2012, 04:22 AM
  6. Online Database Query
    By astradford in forum Access Programming / VBA / Macros
    Replies: 1
    Last Post: 07-12-2012, 02:49 PM
  7. [SOLVED] Best Online Source 4 MS-Excel & Complex database Handling?
    By Mike in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-18-2006, 02:30 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1