473,513 Members | 4,753 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Macro in Excel

116 New Member
Hi
I have a question about a macro I am creating in Excel.

The VB behind the button is as follows:-
Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandButton1_Click()
  2.  
  3. Filename = Range("H66")
  4. ActiveWorkbook.SaveAs Filename:=Filename
  5. End Sub
This quite simply saves the file as the name shown in Cell h66.

What I now need to do is save it to a specific folder. Ie C drive / Estimates. How do I show this please.

Thanks
Jacc14
Aug 10 '08 #1
9 1476
Delerna
1,134 Recognized Expert Top Contributor
Something like this
Expand|Select|Wrap|Line Numbers
  1. Filename = "c:/Estimates/" & Range("H66")
  2.  
Aug 10 '08 #2
NeoPa
32,557 Recognized Expert Moderator MVP
As a full member now, you should know that we expect your code to be posted in [code] tags (See How to Ask a Question and indeed the instructions in the posting window itself).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use the tags in future.

ADMIN.
Aug 10 '08 #3
ADezii
8,834 Recognized Expert Expert
Expand|Select|Wrap|Line Numbers
  1. Dim strFileName As String
  2. Dim strFolderPath As String
  3.  
  4. strFileName = Range("H66")
  5. strFolderPath = "C:\<Folder1>\<Folder2>\"
  6.  
  7. If Len(strFileName) > 0 Then
  8.   ActiveWorkbook.SaveAs Filename:=strFolderPath & strFileName
  9. End If
Aug 10 '08 #4
NeoPa
32,557 Recognized Expert Moderator MVP
Something like this
Expand|Select|Wrap|Line Numbers
  1. Filename = "c:/Estimates/" & Range("H66")
I only noticed this after ADezii posted, but Excel is run mostly on Windows based machines, and for them you will need to use the backslash character (\) in place of the slash (/). It would then be (for your stated folder) :
Expand|Select|Wrap|Line Numbers
  1. Filename = "C:\Estimates\" & Range("H66")
Aug 10 '08 #5
Delerna
1,134 Recognized Expert Top Contributor
I only noticed this after ADezii posted, but Excel is run mostly on Windows based machines, and for them you will need to use the backslash character (\) in place of the slash (/). It would then be (for your stated folder) :
Expand|Select|Wrap|Line Numbers
  1. Filename = "C:\Estimates\" & Range("H66")

oops.
I use html, jscript, vbscript, vba ,c# , access, sql, db2 and various languages at home for 3D. I get syntax differences mixed sometimes. I appologise if it caused any confusion.

That'll tech me for posting before testing.
Aug 10 '08 #6
NeoPa
32,557 Recognized Expert Moderator MVP
Nah. Don't be silly.

I simple little mistake that I'm sure anyone would have spotted had they tried it out. Don't worry about it :)
Aug 10 '08 #7
ADezii
8,834 Recognized Expert Expert
After some serious thinking, scary isn't it, wouldn't this be a better solution for you?
Expand|Select|Wrap|Line Numbers
  1. Dim varFileName As Variant
  2. Dim NewWorkbook As Workbook
  3.  
  4. Set NewWorkbook = Workbooks.Add
  5.  
  6. varFileName = Application.GetSaveAsFilename
  7.  
  8. If varFileName <> False Then
  9.   'For some odd reason, Dialog includes a "." at the end
  10.   'of a File's Name with no Extension
  11.   If Right$(varFileName, 3) <> "xls" Then
  12.     varFileName = varFileName & "xls"
  13.   End If
  14.   NewWorkbook.SaveAs Filename:=varFileName
  15. End If
  16.  
  17. NewWorkbook.Close
  18. ActiveWorkbook.Activate
Aug 10 '08 #8
jacc14
116 New Member
Thanks everyone for your help. I have succeeded in what I was after

Best regards

Jacc14
Aug 12 '08 #9
NeoPa
32,557 Recognized Expert Moderator MVP
You're welcome, and thanks for letting us know :)
Aug 12 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
11091
by: Mrs Howl | last post by:
I don't know if there's even a way to do what I want. I click on a button in an Access form, and it opens an instance of Excel, and opens a workbook and runs a macro that's in it. So far, fine,...
0
2073
by: Alex | last post by:
i have a module in Access which opens an existing Excel file and envokes a macro within the Excel file to draw graphs. now i am trying to convert the Excel macro to an Access one so that the...
8
6538
by: Nick M | last post by:
Hello All, Excellent info here Thanks! I am very new to using access in general and I am on a learning curve. I'm trying to import an excel workbook (with worksheets) into an access db via a...
4
10088
by: Rich Wallace | last post by:
Is there a way to open an Excel file and either respond to or supress the Macro warning window via VB.NET? Dim oExcel As Excel.Workbook Dim sFilePath As String = "C:\DailyReport.xls" oExcel...
3
6973
by: Mr.Doubt | last post by:
I'm trying to run a Excel macro, which uses SOLVER.XLA Add-In, in VB.NET application. When the macro is executed I get the following error message "Solver: An unexpected internal error occured,...
2
17695
by: Senthil | last post by:
Hi All I need to create an Excel report and create a command button and have to run a macro on the click event that will print all the pages in the Excel workbook. I am able to create the report...
4
16066
by: shara | last post by:
Hello, I have a php script that outputs an excel sheet.The user has to download macro every time he wants to run the macro on the excel sheet. Is there anything in php where the code downloads...
1
2240
by: Catbkr1 | last post by:
I have to automatically create some Excel Spreadsheets based on automatically generated .CSV files that are produced overnight. Each .CSV has several columns that need to be deleted. The same...
4
14572
by: mld01s | last post by:
Hi all!! I need help, I have been stuck for a few days on this one. I am trying to open an excel table from a command button in Access. The excel table has an auto_open macro, that is supposed to...
1
6172
MitchR
by: MitchR | last post by:
Good Morning Folks; I have a question that is pretty far fetched but here goes nothing... I am looking to find a way to insert a macro into an Excel command button located in an Access VBA...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.