So I am using VBA-JSON in excel to convert excel data to json file. I have the filepath set to my desktop however I would like other users to be able to run the conversion as well.
I currently have this as a placeholder for the save location:
'change the path below to save where you desire
Set jsonFileExport = jsonFileObject.CreateTextFile("C:\Users\user\Desktop\jsonExample.json", True)
jsonFileExport.WriteLine (JsonConverter.ConvertToJson(jsonItems, Whitespace:=3))
Exit Sub
I've done research and I've seen mentions of .specialfolders but I am uncertain where to put it in my code. Any help would be appreciated.
Related
I want to display dynamically .pdf files like pictures in a report, it should look like this:
i already tried with webbrowser, but then it doesn't show up in the preview or when i print the report out...
I also tried a ole unbound object, also no success, here the code i had in the Report_Load event:
Dim vPath As String
vPath = GetNewestDocument(Me!artNr)
'Returns path for pdf file, about:blank if there is no file.
If vPath = "about:blank" Then
Me!PDFBrowser.visible = True
Me.PDFBrowser.SourceDoc = vbNullString
Else
With Me.PDFBrowser
.OLETypeAllowed = acOLELinked
.SourceDoc = vPath
.SizeMode = acOLESizeStretch
End With
End If
EDIT:
With "I want to display dynamically ..." i meant to change dynamically pdf's in the Report.
EDIT 2:
I just found out that the type of the OLEunbound object is embedded, but i think this one should be linked as i read in other Forums:
When i try to Change it gives error: "This property can not be changed because it is read-only"
You could get a licensed version of Adobe Acrobat (not Reader) and control it programmatically to capture the images you want.
Alternatively, you could use the VBA Shell Function to call a command-line PDF converter like 2Jpeg to programmatically (and dynamically if necessary) convert the PDF to an image (see this), or even "print" the PDF to an image file using the correct driver (see this).
Once you have an image file, you can easily load the created image to your Access form with VBA, perhaps with this.
Without further information (and answers to my previous questions) I can't offer more suggestions at this point but I hope that helps!
I am looking for a VBA code to run multiple saved imports in MS Access 2010. I used DoCmd.RunSavedImportExport "*" but gave an error.
I know I am doing something wrong here. Please understand I am a newbie to VBA. I have almost 8 saved imports in .csv formats in a specific location. All I want is to automate it through VBA.
i guess you have taken all other necessary steps already.
loop through the saved import/export and execute them one by one.
something like:
pseudo would be:
loop through the import/export and execute it manually.
in code would be:
Dim i As Integer
For i = 0 To CurrentProject.ImportExportSpecifications.count - 1
Debug.Print CurrentProject.ImportExportSpecifications(i).name
DoCmd.RunSavedImportExport CurrentProject.ImportExportSpecifications(i).name
Next i
EDIT
Your ImportExportSpecifications details are saved as XML format and you can access that information via
CurrentProject.ImportExportSpecifications(i).XML
within the XML you will find the path = "your file.xlsx". Do a string job to extract the path and validate the file ending and implement your code.
I am attempting to create a table within a database which store all of the documents related to the database "in it". What I really want to do is have a file uploaded and have vba code which copies the file to a network location, renames the file by concatenating two fields from the document table form (eliminating the issue of duplicate file names in the external location), and then stores the file name and file path in a file path field in the table. I am very new to access and vba so I am having difficulty getting everything to work. The code I currently have is below:
Option Compare Database
Private Sub Command15_Click()
Dim f As Object
Set f = Application.FileDialog(3)
f.AllowMultiSelect = False
If f.Show Then
For i = 1 To f.SelectedItems.Count
sFile = Filename(f.SelectedItems(i), sPath)
MsgBox sPath & "---" & sFile
Next
End If
End Sub
Public Function Filename(ByVal strPath As String, sPath) As String
sPath = Left(strPath, InStrRev(strPath, "\"))
Filename = Mid(strPath, InStrRev(strPath, "\") + 1)
End Function
I can not seem to get a handle on how to move, rename by concatenating the two fields from the form, or store the path in the path field of the table. I have been to the following locations to obtain what information I could
ms access browse for file and get file name and path
VBA to copy a file from one directory to another
I am currently using Microsoft Access 2010, and I do not wish to use the file attachment field type because of database size constraints. Currently I press a button and a file explorer appears to navigate to the file being uploaded, and the path and file name are entered into strings. After this point I am lost. If any other information is needed please let me know. Thanks in advance for the assistance.
I believe your approach to managing the documents is right. In most cases, it doesn't make much sense to store documents in the database itself when the filesystem is a more suited to this job.
What you are doing is fairly straightforward but the main complexity will come from the correct management of the various paths and filenames and extracting the right information from them.
It can become tricky if you're not using some helper functions to to dissect and recompose the various bits of the paths.
I have created a sample database that has a few functions. Might not be exactly in line with what you need but you can easily play around with it to suit your particular case.
The sample database includes a Tools VBA module that has a few useful functions to split a Path into its constituents.
Basically, the database has 2 forms.
The main form allows you to set the network path where the files are to be saved.
You can then select a pre-defined Account number (listed in the Account table) associated with a document, then click the upload button.
This creates a new record in the Document table and opens a form where you can edit the document title and click a button to upload a file to the server.
The file selected by the user is copied to the server after its path has been transformed.
I took the assumption that the file would keep its original extension, the filename would be renamed to the ID of the Document record where the file information is saved (like 5845.pdf) and that the folder where the file is saved on the server would be the account number, so that a source file selected by the user
C:\Users\user\Desktop\SuperSecretFile.pdf
would be saved as, for instance:
\\docserver\files\123-55547\5845.pdf
The Main form also allows you to update an existing record, open the file from the server, open the server's folder where the file is located or even copy the server file back to the user's computer with the original name of the file.
I'll let you play around with it. Let me know if you have any issues.
I have a number of local JSON files which I am trying to open as a string using VBA in order to extract specific information from them into Excel.
I have seen a similar exercise work when the files are accessed by HTTP (using New.WinHTTP.WinHTTPRequest), however when I've tried to adapt this using a FILE:/// prefix it won't work.
Is there a different Excel method I can use to access the string content of the JSON file?
Cheers
Chris
Reading from disk is not really something you would adapt code that reads from a url to do.
You can load it into memory with;
dim hf As integer: hf = freefile
dim data as string
open "c:\bla\bla.bla" for input as #hf
data = input$(LOF(hf), #hf)
close #hf
debug.? data
There are many results for JSON parsing in vba.
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.