Modules & VBA :: Setting Path When Saving Excel Workbook
Nov 1, 2013
I am trying to write some code to open an existing excel form, populate it, and save it with a custom filename in a directory that is built using variables I have declared.
The only part I am having difficulty with is setting the pathname. Here is my code:
Code:
'Build path to save file to
spath = "S:ContractsGeomatics LABSigned" & Company
'Build File name
Filename = "" & reservationNumberforForm & " " & Company & "-Payment Schedule"
'Save the payment schedule to the S: drive
'xlApp.ActiveWorkbook.SaveAs Filename:="S:ContractsGeomatics LABSigned" & Filename, FileFormat:=xlOpenXMLWorkbook
xlApp.ActiveWorkbook.SaveAs Filename:="" & spath & " " & Filename, FileFormat:=xlOpenXMLWorkbook
xlApp.ActiveWorkbook.Saved = True
I want to pass a string aPath contains path of the active workbook to access vba module or sub. Below is my excel vba code that will open access db form. How do i pass the string value to access vba.
Code: Dim aPath, aDbase, aDSource, aTable, exePath As String Dim fileParam As String aPath = ActiveWorkbook.Path aDbase = "near_14.accdb" aDSource = aPath & "" & aDbase
I would like to open an Excel workbook from MS Access and clear cell contents, or just delete some records in a specific worksheet.
If you open the test workbook, cell contents in RAW need to be deleted by calling from Access.
I have produced some code but it's partially working.
Code: Sub TestFileOpened() ' Test to see if the file is open. If IsFileOpen("test.xls") Then ' Display a message stating the file in use. MsgBox "File already in use!"
[Code] ....
If you put this in a standard module in access, the function works, but the part that doesn't work is where it says "activesheet". It somehow tries to recognize it as a variable, but it's not going to be a variable.
I have a question about the best way to go about linking an excel workbook to an ms access table? I have researched hyperlinks and attachments and ole objects and I am not sure what is the best option. I believe hyperlinks will be best, because the attachments will bloat the database, but I am not sure how to go about doing that in vba? My process is such:
1)Users enter project information 2)Users enter the sample information for each project 3)The project and sample information is combined by a query 4)The user clicks a button to print forms, which runs the query and opens an excel workbook template. 5)The data is exported to a specific sheet in the workbook 6)Using vba in excel, the data is used to populate cells in different sheets depending on critera.
After all of this is accomplished, I need the user to SAVE AS the excel workbook and it needs to be "attached" to the ms access 'project' table. I am not sure what is the best way to link this back to the database. I would like to automate it with vba if possible.
Hello, sorry to post again my question but just cannot find a solution. I have a table and would like to copy data into a template in excel. I know that the code will have to make a copy of the template and then copy the data into the new workbook into sheet1.
My table (table1) has 3 fields: SSN, FNAME and LNAME. I want to copy these fields into cells B1 (for SSN), B2 (for FNAME) and B3 (for LNAME). I will use a combo to select the recorset to copy.
My problem is how to copy data into the template. I understand that it is necessary to run a copy of the template and then copy the data into the new xls file.
Is there a way I can do this via code? Code help is appreciated. Thank you.
Any definitive way of exporting a query to an Excel file and then saving it as a new file without saving over the original.
I've tried to remove any confidential info from the code below so it's not exactly the same.
Code: Dim XLApp As Excel.Application Dim XLSheet As Excel.Worksheet Dim tmpRS As DAO.Recordset Dim strFolder as String strFolder = ("C:Profiles"& [Name] & "")
[Code] ....
The error seems to be with the SQL statement although that may just be the first error that it got to. I read that you can't refer to a Query if it has a criteria and that you have to write the SQL directly into the code.
I am using Access to save an Excel file in a particular directory. The code was created about 10 years ago and hence saves the file with .xls extension and I would like to save with a .xlsm extension. If I just change the .xls to .xlsm, in the code below, the file is saved but the Compatibility Checker comes up (I would like to stop this) and when the file is reopened I get an error message stating there is a file extension problem and the file won't open.
If a File exists in CurrentProject.Path & "Book1.xlsx" , I want to delete it and create a new file . How can I do it using MsAccess vba .Also how to create a new Workbook Book1.xlsx with only one WorkSheet called Sheet1
I've build an Excel workbook that contains extensive use of VBA code for UserForms, Control Buttons, etc. and also contains several sheets that are formatted as Tables and function as databases. We've outgrown Excel's capabilities and need to move over to Access.
I need to import 5 sheets from an Excel Workbook into one table. At the moment I have code which goes through each sheet and imports them. Using the Import wizard only enables you to import one sheet.
I have a procedure in Access that exports three reports to Excel, combines them in a single workbook, and then applies Excel formatting to some of the sheets. This procedure works the first time, but if I run it again it fails. In particular, I notice that things like "ActiveCell" and "Selection" will continue to refer to the previous workbook (dim xlWkb), even though I've activated the current worksheet/workbook.
Code: Dim xlApp As Excel.Application Dim xlWkb As Excel.Workbook Dim xlBwkb As Excel.Workbook
[code]....
'BillingTemp, etc. are defined earlier in the procedure. I essentially am exporting Access reports to temporary Excel files, and then opening the files and putting them in a single workbook.
Set xlBwkb = xlApp.Workbooks.Open(BillingTemp) xlBwkb.Sheets(1).Copy After:=xlWkb.Sheets(1) xlBwkb.Close False Set xlBwkb = xlApp.Workbooks.Open(PrismTemp) xlBwkb.Sheets(1).Copy After:=xlWkb.Sheets(2) xlBwkb.Close False
[code]....
'After combining the exported reports into one Excel workbook, I apply some formatting to some of the sheets.
Dim i As Integer Dim rng As Range Dim b As Range Dim lastRowB As Integer Dim Indication As String Dim ws As Worksheet
I am using Office 2007 and trying to export a table in Access to a Macro-Enabled workbook in Excel. Unfortunately, when I go to export the table, my file does not show when I browse for the file and .xlsm doesn't look like it's a supported file extension. I have looked around and noticed others have this problem as well. One solution was to use save the Excel file as a 97-2000 file since it doesn't change the file extension based on having macros. However, I can't do this because then I lose functionality with tables and other things on my spreadsheet. I need the data in Excel to be updated every month. Is there any way to do this in Access? I'm going to explore using sharepoint. My DB options are limited to Access and Sharepoint. I don't have access to Oracle or SQL Server or MySQL etc.
I'm using GHudson's A Better Mouse Trap code. It works great. However, I added other code from http://www.databasedev.co.uk/image-form.html to get and save the path to image files and now I think there is a conflict between the sets of code.
The Images tab on the form frm_CreateNewSpec is where I have problems. The error messages are definitely from Mouse Trap...I just don't know how to resolve the problem.
I've probably missed something simple, but don't know what.
Any and all assistance is greatly appreciated by this novice.
Here's my problem. I run a database every monday that has several (more than 15) reports as the outcome. Due to the massive amount of information we can't build the data up every week. We need to overwrite the tables and recreate the "Reports" every week. The department I am creating this for wants to keep a snapshot on the computer of the 15+ reports instead of printing them out. But instead of simply creating a snapshot of each individual report he would like to see them in the format of one file with multiple sheets. The one file would be labeled the date the reports were created and each individual sheet would be labeled the name of the report. For example, This past monday when we rant he Db the file would have been lbld 10-3-05, and one of the many sheets would have been labeled "Selects", or "Rejects" or "Cost" and so on. Does anyone have any suggestions?
I'm importing data from Excel to Access using Access VBA which works fine that sheet name is first sheet in workbook. However, if multiple sheets exists in the workbook and that particular sheet can be 2 sheet, 3 sheet or any sheet. In that case how to search particular sheet name and import in access. Below is the code I have used for importing the data.
I have an access query with around 10 columns. One of the columns is city. There are total of 5 unique cities. I need a macro for the button in the access report that will export the data from the access query to the ONE excel workbook in such a way that each city filtered data from access is exported to city name worksheet. So Excel file would have in total of 5 worksheets with the relevant city data.
I have some vba code that exports the results of a query to a specific excel workbook. Code in this workbook then takes the exported data to "fill out" areas in the workbook. My staff will then use this workbook to perform analysis on a project. After they have completed the analysis, they will then save the excel workbook, and another person will then validate this excel and turn it into a PDF to send as an email attachment.
My question is, when my staff saves the excel workbook, is there a way they can save it directly to the access database? If not, would there be a way to use vba to "attach" this excel workbook to the appropriate record in the access db for future use?
I have a workbook which is already opened and I want to close it. the code that i have is (see below) is not working.
Code:
Function CloseExcel(sExcelFile As String) As Integer Dim XLapp As New Excel.Application Dim ObjXL As Excel.Workbook On Error GoTo ErrorTrap Set ObjXL = XLapp.Workbooks.Open(sExcelFile)
I'm using the MS Access 2010 ExportwithFormating action to export three tables to a single MS Excel 2010 workbook. The action overwrites the first excel worksheet each time instead of saving all three worksheets in a single excel workbook.
How can I export three tables into a single excel workbook.
I have a excel object I have opened, and want to copy a query into a named range on the workbook.
heres the start have made
Sub openExcel() 'WillR - opens the specified Spreadsheet Dim xlApp As Excel.Application Dim xlWB As Excel.Workbook Set xlApp = New Excel.Application With xlApp