Recently I am trying to export the data within each list item on SharePoint to Excel using VBA. Below is the list.
And if you click on each one it looks like:
So the data I crossed out are the values that I want them to be exported to an Excel Spreadsheet.
I know how to export the whole list of to excel, the code is:
Sub ImportSharePointData()
Dim objMyList As ListObject
Dim objWksheet As Worksheet
Const SPServer As String = "http://ln- sharepoint.XXXintra.net/XXX/XXX/XXX/_vti_bin"
Const LISTNAME As String = "{06AAB69F-XXX-XXX-XXX-8F677FE38D76}"
Const VIEWNAME As String = "Agreement"
ActiveSheet.ListObjects.Add SourceType:=xlSrcExternal, Source:= _
Array(SPServer, VIEWNAME, LISTNAME), LinkSource:=True, Destination:=Range("A1")
End Sub
Now I want data in each individual item in this list e.g. Item with ID 367, exporting the field of Counterparty Name, CSID etc to excel.
Also, it looks like these data are filled in by users into forms on SharePoint that are designed using InfoPath.
Is there anyway that I can do this without using the designer level of access?
Thank you very much in advance for any solution or advice.
As long as the desired fields on the InfoPath form are directly associated with SharePoint columns, the data will be available to display and export.
Notice that you specify which view you want when you export the list to Excel.
Const VIEWNAME As String = "Agreement"
With this in mind, simply create a new public view of the list that shows all the columns of data that you want to export. Then export that list view instead.
Related
I'm wondering is it possible to dynamically export specific MS Access tables to a CSV file using VBA?
I'm able to export all the tables to a CSV / Excel file but the ask I was given once this was in place, is to be able to export a specific set of tables from the MS Access database a CSV file and not the entire set of tables.
Ideally the user would access a Form which they'd be able to select the tables they would like to export and click a button that would run the script.
Is this possible using VBA or is it to complex? Any advice or resources would be appreciated. Thanks!
You can use this query to populate your listbox:
SELECT MSysObjects.Name
FROM MSysObjects
WHERE ((Left([Name],4)<>"~TMP" And Left([Name],4)<>"MSys" And Left([Name],2)<>"f_") AND ((MSysObjects.Type)=1));
To list the tables in VBA:
Public Sub enum_tables()
Dim td As TableDef
For Each td In CurrentDb.TableDefs
If Left(td.Name, 4) <> "MSys" And Left(td.Name, 4) <> "~TMP" Then
Debug.Print td.Name
End If
Next
End Sub
The matches between the selection in the listbox and the list from 'enum_tables', are the ones you want to export
I've wrote a macro that takes some data from e-mail body and then instert this data into SharePoint Table.
Scrapping the e-mail body works fine, as well as inserting data to SharePoint - but the inserting part takes a long time (about 2 minutes for each execute).
Here is the code:
Public Const sDEMAND_ROLE_GUID As String = "{111111111-2222-3333-4444-111111111111}"
Public Const sSHAREPOINT_SITE As String = "https://randomsharepoint.com/sites/test/"
Sub insertIntoSharePoint()
Dim cn As ADODB.Connection
Dim sConn As String
Dim sSQL As String
sConn = "Provider=Microsoft.ACE.OLEDB.12.0;WSS;IMEX=0;RetrieveIds=Yes;" & _
"DATABASE=" & sSHAREPOINT_SITE & ";" & _
"List=" & sDEMAND_ROLE_GUID & ";"
Set cn = New ADODB.Connection
sSQL = "INSERT INTO [TEST TABLE]([Test1], [Test2], [Test3], [Test4], [Test5], [Test6], [Test7], [Test8], [Test9], [Test10], [Test11])" & _
"VALUES ('TestVal1', 'TestVal2','TestVal3','TestVal4','TestVal5','TestVal6','TestVal7','TestVal8','TestVal9','TestVal10','TestVal11');"
With cn
.ConnectionString = sConn
.Open
.Execute sSQL 'This is the line that takes most of the runtime'
.Close
End With
Set cn = Nothing
MsgBox "Item successfully added to SharePoint"
End Sub
Is there any way to optimize this code?
Or the slow execution depends only on internet connection/weak computer?
Or do you have any other solution to solve the main problem? (scrapping e-mail body and inserting it into SharePoint List)
Well, VBA is inherently slow. Maybe you can just import everything from Outlook to Access/Excel, and then source your SharePoint data from Access/Excel.
On the site where you want to add a spreadsheet based list, go to Settings Office 365 Settings button and then click Add an app.
In the Find an app field, type spreadsheet and then click the search icon Search box magnifying glass icon .
find an app field with Spreadsheet typed in and search button highlighted
In the search results page, click Import Spreadsheet.
Import spreadsheet app highlighted in New apps dialog
In the New app page, type a Name for the list.
The name appears at the top of the list in most views, becomes part of the web address for the list page, and appears in site navigation to help users find the list. You can change the name of a list, but the web address will remain the same.
New app dialog with name and file location filled in, import highlighted
Type an optional Description.
The description appears underneath the name in most views. You can change the description for a list at any time using list settings.
Browse to or type the File location of the spreadsheet. Click Import when done.
The spreadsheet will open in Excel, and you'll see the Import to Windows SharePoint Services List window.
In the Import to Windows SharePoint Services List window, choose Table Range, Range of Cells, or Named Range. If you want to select a range manually, choose Range of Cells, and then click Select Range. In the spreadsheet, click the upper left cell, hold down the Shift key, and select the lower right cell of the range you want.
Excel spreadsheet with range highlighted
The range will appear in the Select Range field. Click Import.
Import to spreadsheet dialog with Import highlighted
After you import a spreadsheet, check the columns of the list to make sure that the data was imported as you expected. For example, you may want to specify that a column contains currency instead of a number. To view or change list settings, open the list, click the List tab or click Settings Office 365 Settings button , and then click List Settings.
The spreadsheet data will appear in a list in SharePoint.
List in SharePoint Online
See the links below for more info.
http://3sharp.com/blog/load-excel-data-into-a-sharepoint-2013-list-fast-and-easy/
https://technet.microsoft.com/en-us/library/2008.04.access.aspx
I need help with how to work on text file (like database).
I create excel GUI (with macro's), that search imputed string in sheets with lots of data and display entire row with matching string (for people with installed MS office)
Now I must create alternative VB.Net application working only on tab delimited text files (without ADO.Net) for people who haven't installed MS office, and I don't know how start to work with it.
import them? if yes, then how.
working directly on them? if yes, then how.
My text files is exported excels files/sheets to tab delimited .txt, with loots of columns (100+) with headers, and lots of rows 500+
need help :)
thx
If you want to get the headers from the first line of the file then do this ...
Sub Main()
Dim dt = New DataTable
Dim lines = File.ReadAllLines("TextFile1.txt")
Dim headers = lines(0).Split(vbTab)
For Each header In headers
dt.Columns.Add(header)
Next
For Each line In lines.Skip(1)
Dim parts = line.Split(vbTab)
dt.Rows.Add(parts)
Next
End Sub
I'm trying to save a Microsoft Word 2013 document with a specific filename.
I created a Word form that a client fills out.
I am using the following: DEVELOPER -> Controls -> Plain Text Content Control DEVELOPER -> Controls -> Date Picker Content Control DEVELOPER -> Controls -> Drop-Down List Content Control
I would like a macro to save the document with the name of one of the fields in the form.
Example:
below are fillable content fields.
client reference: A1B2-345
date: August 17, 2015
type: metadata
I would like to save the file as:
A1B2-345_17082015_metadata.DOCX
Start by giving each of your controls a Title. You can do this by clicking on your control in your document and then click Properties on the Developer ribbon. The first field on the Properties window is Title. Give each one of the controls you need to access a unique title. In the example below, I'm using MyText, MyDate, and MyDrop for the text, date, and drop-down controls, respectively.
Then you can access each control in VBA by using the SelectContentControlsByTitle() function. As long as you're using a unique title, this function will return a collection containing only a single control so we can just retrieve the first item from the collection (index (1)). Here's how this would look:
Dim strText As String, strDate As String, strDrop As String
strText = ThisDocument.SelectContentControlsByTitle("MyText")(1).Range.Text
strDate = ThisDocument.SelectContentControlsByTitle("MyDate")(1).Range.Text
strDrop = ThisDocument.SelectContentControlsByTitle("MyDrop")(1).Range.Text
The Range.Text ending is what grabs the current text/value from the control.
Now that you have your three pieces of information, you can concatenate them into one string using the concatenation operator (&):
Dim strFilename As String
strFilename = strText & "_" & Format(strDate, "ddmmyyyy") & "_" & strDrop & ".docx"
And, finally, save it:
ThisDocument.SaveAs strFilename
It should be noted that the code provided above will not work properly if you are generating the form based off a template (.dotm). The following lines that include the ThisDocument.SelectContentControlsByTitle need to be changed to
ActiveDocument.SelectContentControlsByTitle otherwise the code will pull the place holder text from the content control.
Is there a way to export data that has been populated into a VB.net forms application split by Tabs? I have a large program that connects to a SQL database and runs many queries to populate Labels within the application.
I would like to export the data into an Excel Sheet over different tabs per Tabular Page in the Form application. If this is not possible then a generic .csv export will be fine.
I am running my SQL query and importing it into Labels like this -
Dim myCmd23 As New SqlCommand("MySQL Query", myconn)
Dim myDataA23 As New SqlDataAdapter(myCmd23)
Dim myDataT23 As New DataTable()
Dim myDataS23 As New DataSet()
myDataA23.Fill(myDataT23)
DataGridView1.DataSource = myDataT23
Dim result23(2) As String
result23(1) = DataGridView1.Rows(0).Cells(0).Value.ToString
result23(2) = DataGridView1.Rows(0).Cells(1).Value.ToString
Label1.Text = result23(1)
Label2.Text = result23(2)
There are many of these SqlCommands carried out. The Form application looks like such -
The seperate tabs are shown above and i would like to try and seperate this data in the Export?
The Dates and Filters are taken into account within each seperate SQL query so they are no bother.
If anybody has a possible solution that would be great.
Thanks
Greg
There are several blogs about exporting datatables to Excel in VB.NET here