Manipulating Access VBA IDE methods from VBScript - ms-access

I'm trying to write a VBScript that will export and import the code modules from an Access MDB file to text files.
From within the app I can loop through the DAO Container & Documents and use the 'undocumented' Application.SaveAsText method, but can I do it externally?

Basically it is all COM, but the COM interface doesn't expose methods for opening files, using MDWs for security, etc, but minds greater than my own have found a solution to the problem at http://www.mvps.org/access/modules/mdl0036.htm.
Once I've got a reference to the database, I can then use the techniques Remou and HansUp mention as normal.

It's all COM, so pretty much anything you can do from VBA in the IDE, you can do from a .vbscript file externally.
Set accessApplication = CreateObject("Access.Application")
' then do what you do from the IDE

Related

How to modify Access DB File which is in sharepoint Document Library

I am having accdb file(Ms access DB file) in sharepoint Document Library. I want edit the file in browser or without downloading the file to the local.
I am able to view the file but not able to Edit it.
Need help
Access doesn’t really work this way. You can store the data tables in Sharepoint, but you still need the local access file to interact with it. You can link to data tables in Sharepoint. Instead of creating a brand new table, you import the data source.
Microsoft does have a newish program out now called PowerApps that may help you accomplish something closer to what you’re describing.

How can I use VBA code to convert a .html file to an existing .xlsm file?

I have software that generates a 2x 25,000 table of numbers in an .html format. My current process is opening the .html, saving as Excel workbook, etc.
The goal is to automate the process, import the data to Excel, and generate graphs and box charts. I have used macros to accomplish the latter but I am struggling with getting the .html data into the existing .xlsm.
I have found this code, from a helpful thread on Stack Overflow:
Sub Open_HTML_Save_XLSX()
Workbooks.Open Filename:="C:\Temp\Example.html"
ActiveWorkbook.SaveAs "C:\Temp\Example.xlsx", xlOpenXMLWorkbook
End Sub
However, I'm not sure how to use it. I've been using custom made keyboard shortcuts to access my macros such as Ctrl+Shift+Q. I also don't know how to edit it to suit .xlsm.

Convert .CSV to .XLSX using command line

I'm looking for a way to batch-convert a series of .csv files to .xlsx using the command line.
I have tried a bunch of different VBScripts that I found but they all seem to be converting .xlsx to .csv and not the other way around.
Here is the closest one I could find but again it's .xlsx to .csv:
if WScript.Arguments.Count < 2 Then
WScript.Echo "Error! Please specify the source path and the destination. Usage: XlsToCsv SourcePath.xls Destination.csv"
Wscript.Quit
End If
Dim oExcel
Set oExcel = CreateObject("Excel.Application")
Dim oBook
Set oBook = oExcel.Workbooks.Open(Wscript.Arguments.Item(0))
oBook.SaveAs WScript.Arguments.Item(1), 6
oBook.Close False
oExcel.Quit
WScript.Echo "Done"
Any ideas?
Disclaimer: I have written CSV2XLSX available as open-source at https://gitlab.com/DerLinkshaender/csv2xlsx
You may want to try an external tool like the one above. Why?
Advantages:
may be used even where Windows Script Host is blocked.
independent of operating system, so you may use a familiar tool with then same set of options on every OS (save brain memory :-) ).
no installation of Excel or LibreOffice etc. needed, so you don't have to care about installing additional modules or languages.
specifying several CSV parameters as command-line parameters makes the tool "SysAdmin-friendly", as they do not have to dig thru source code.
you may even specify line or column ranges for the csv data.
the xlsx file format is very complex, writing it without resorting to an installation of an office package is not for the faint of heart.
better suited for batch processing as the tool can be integrated in the OS-specific loop logic.
I tried to provide a useful set of command line flags with DevOps/SysAdmin in mind, many existing scripts lack good control via command-line options.
only pre-requisite is that the ".csv" must be lower case in the filename:
Dim file, WB
With CreateObject("Excel.Application")
On Error Resume Next
For Each file In WScript.Arguments
Set WB = .Workbooks.Open(file)
WB.SaveAs Replace(WB.FullName, ".csv", ".xlsx"), 51
WB.Close False
Next
.Quit
End With
WScript.Echo "Done!"
For Windows, I recently responded to a similar question on SuperUser.com.
https://superuser.com/a/1011154/326177
I think Total CSV Converter is the least expensive option with the most features. It doesn't even require Excel to be installed and can can output CSV data to JSON, Access, DBF, XML or SQL.
http://www.coolutils.com/TotalCSVConverter
CSVConverter.exe <source> <destination> <options>
Here's a open-source tool for Windows machines I created using the NPOI libraries that does simple delimited file to XLS/XLSX conversions without Excel needing to be installed on the machine. The binary is in Bin/Debug if you don't want to build it yourself. All the necessary libraries are included in the executable so it can operate standalone.
https://github.com/nmolinos/csv2excel
Are you on Windows or Linux/Mac?
I might have a solution for you either way.
Here is the solution to your problems without the programs commented below:
https://social.msdn.microsoft.com/Forums/en-US/74df1378-7c0c-4c0f-b174-fa97a5c2969b/convert-csv-to-xlsx?forum=Vsexpressvb
EDIT
So here is the basic solution:
Basically you apply a filter (which in the case would be the xlsx filter) from the directory where your file is located.
Nvm this I just saw you are on Windows
./directory --headless --convert-to xlsx:"Calc MS Excel 2007 XML" file.csv
in this case "Calc MS Excel 2007 XML" is the filter.
That works for single files, let me add batch in a sec.

Merge multiple access reports to one pdf file using vba

I wan't to merge multiple access reports to one pdf file using vba code. This vba code needs to work on the computers at my work. These computers only contain Adobe Reader, and I am not able to install Acrobat because I am not Administrator. So now my code generates for all the reports a seperate pdf. I had some code to merge these pdf files to one pdf file where I use 'Acrobat.CAcroApp'. But i get an error on line:
Set AcroApp = CreateObject("AcroExch.App")
I think I am not able to do this cause the computers only have Adobe Reader installed. Is there a possibility to create one pdf file for multiple reports/pdfs without using Acrobat.
Thx in advance
2 solutions.
Make a master report that has each individual report embedded as a sub report. If it's just a few, it should work fine, but too many may bog down / crash the application.
Here's a VBA way of doing it here.
Without acrobat reader this is indeed not going to work. I, however, am using the following dirty workaround for users without acrobat;
Export all your reports to rich text ("*.RTF" format) in the same folder. Afterwards, you open a word application via access vba, and loop through the RTF files and then copy them into your word file, with a page break after every insert. Then, you save the word document as a .PDF file.
This is a method prone to errors, so if a more experienced user has a better way, please do tell. I'm interested as well!

Storing PDFs in MS Access Database using Forms

I need to store PDF files in an Access database on a shared drive using a form. I figured out how to do this in tables (using the OLE Object field, then just drag-and-drop) but I would like to do this on a Form that has a Save button. Clicking the save button would store the file (not just a link) in the database. Any ideas on how to do this?
EDIT:
I am using Access 2003, and the DB will be stored on a share drive, so I'm not sure linking to the files will solve the problem.
We have several databases that contain 10's of thousands of documents (pdf, doc, jpg, ...), no problem at all. In Access, we use the following code to upload a binary object to a binary field:
Function LoadFileFromDisk(Bestand, Optional FileName As String = "")
Dim imgByte() As Byte
If FileName = "" Then FileName = strFileName
Open FileName For Binary Lock Read As #1
ReDim imgByte(1 To LOF(1))
Get #1, , imgByte
Close #1
If Not IsEmpty(imgByte) Then Bestand.Value = imgByte
End Function
In this case, Bestand is the field that contains the binary data.
We use MS SQL Server as a backend, but the same should work on an Access backend.
If you used the same concept but upsized to SQL Server- storing PDFs inside of an Image datatype (or varbinary(max)) then you could SEARCH INSIDE THE PDFs using Full Text Search.
I show that Microsoft says you can do this for any file type where you can register an IFILTER product.. and I just was at the Adobe website the other day and say that their Acrobat IFILTER is indeed FREE.
Maybe this will help: ACC2000: Reading, Storing, and Writing Binary Large Objects (BLOBs).
What they do: Read a file in chunks and add it to a blob using a VBA function.
A field of OLE Object, by default would use a Bound Object Frame on the form. Right click on it and you can Insert an object. It comes complete with browsing for the file. Double-click on the field and the actual document will open.
I recommend going with David's advice and link. Unless you have a need to transfer a single file and want all the PDF's included. Size and performance will be an issue.
If security is an issue and the Access file is the only control you have (You are unable to set security on the folder containing all the linked files.), then you would have to embed.