I am trying to have the user hit a button and save the workbook in a newly created directory. Currently it creates the new workbook and the new directory with the correct names, however the workbook is not in the newly created directory.
I have an issue with saving the file at the desired location below is the code i have currently used . I have given the destination as "D:New folder". The new file does get saved at location "D:" but not inside the "D:New folder", instead names the file as "New folder".
My code in the first workbook generates a new workbook with a variable in the filename, then copies the cells from the first workbook to the newly created workbook. This code is working properly when used in a draft worksheet I use for testing. As soon as I put it in the master file, an error message pops up "Runtime error 1004 : select method of range class failed". Then the debug sends me to the line " Cells.Select ". What should I be looking for, why does my code work on one file but when i put it in another one it doesn't ?
Private Sub CommandButton1_Click() Dim line_counter As Long Dim prm_line_value As Boolean prm_line_value = False Do prm_line_value = Sheets("Rate").Cells(1 + line_counter, 1).Value line_counter = line_counter + 1 Loop Until prm_line_value = False line_counter = line_counter - 1 Dim Wk As Workbook Dim number_of_new_wb_needed As Integer If line_counter < 5000 Then.....................
I originally posted this in the "Excel New Users forum" - i guess that was an error, but I'm very new (second post) and very new to VBA in general - so please be gentle!!
I've created a macro which opens a workbook, creates and renames a new worksheet, and moves it to the end of the workbook.
I then need to paste into this new worksheet a selection from another workbook.
How would I specify in the code that the selection needs to be pasted into the newly created tab?
After programmatically creating a new activex checkbox, I want to create a sub for it's click event. I have given the object a name, and fortunately the code for it's click event is a one-line call of another sub, but how?
The sub would look like the following except be named after the new control (obviously), and yes, it is just the number in the name that changes:
I attach an example worksheet with the code I have thus far.
In my workbook I have other sheets, one of which changes and updates a specific one each time a new client's data is entered on said other sheet. Because I want to save the specific client's data and not lose it when another client's stuff is entered on this other sheet, I copy the sheet where the data is summarised (I called this sheet "Sheet to Copy From") to a newly inserted sheet and use Paste Special, Values Only to change all functions /f ormulae / Links ect to values.
I then change the name of the sheet to the name of the client.
I then use this sheet name / cell value to polulate a range on another sheet (Next Empty Cell) as a Hyperlink to the newly created sheet above. This sheet I called "Table of Contents".
how to code the hyperlink. Using Macro Recorder uses the specific case's names, but the Tab name to be used as Hyperlink value will always be the name of a new client,
I created with code to copy a template, hide that template, and pop up a box to rename the copy, I noticed she clicked "Cancel" on the InputBox. When she did, she received an error (400). What I would like to do is when the "Cancel" button is clicked, the newly created copy would be deleted. Is this possible?
Here is the code for my full "Create New Project" sheet procedure:
Sub CreateNewProject() 'This code will copy the Project Data sheet, hide it and then 'rename the new copy to the MSA number. Code also prompts user for 'MSA Number and fills that in on the form. Dim RenameSheet As String Dim oSheet As Worksheet With Sheets("Project Data") .Visible = -1 .Copy After:=Sheets("FHWA Quarterly Report") End With...............
Using Excel 2010. I'm writing a macro that sets up a workbook to be used for estimating at the beginning of a project. In the code I need to create multiple tables (formerly known as "lists") in the workbook. Then later in the code I need to refer back to those newly created tables. Currently, the code that creates the table is part of a loop that creates the table on many different worksheets. The problem of course, is that I have to name the Table, and then it won't create a table of the same name on the next sheet. Then, later in the code, I need to make adjustments to the table that was just created before looping to the next sheet.
Is there a way to create a table without giving it a constant name? Or by giving it a name that builds off of other info in the sheet? For example, I would be good with the naming the table after the sheet name: "Sheet1_Table" or such.
Code: Sub Auto_Open() ' Dim sht As Worksheet If Range("A1") = 1 Then
I'm working on a Tool, where every change should be saved in a new Version. So if the user changes any number, he should click my selfcreated save-button, which takes todays date in the filename (no problem so far).
I tried to disable the "normal" save-button with:
Code: Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Cancel = True MsgBox ("saving cancelled!") End Sub
Unfortunately this code won't allow my own button to save too. Is there any other way? Maybe sth like if "normal" saving is used, then automatically activate a makro (which is also on my button) instead of just saving?
I have code that creates a row of controls on an MSForms.Userform at runtime.
I would like the user to be able to save these controls so that they are available the next time he opens the form. The user would be able to add or delete a row of controls and save them AND the values that he has set. This allows great flexibility for each session using the form.
The values aren't a real problem - I've been using the SaveSettings function for the design time controls values. The runtime controls are combobox, textbox, listbox, checkbox.
I don't want to design-time build the controls and just toggle the visible property (not a good solution for my app).
I have a workbook that has twenty data sheets. The user presses a button that copies they're specified sheets to a new workbook and prompts them with the SaveAs Dialog. How do I code it so that if they press the CANCEL button on the SaveAs Dialog it closes the created spreadsheet without saving it?
This code works fine, as long as Excel isn't pointed to the default directory. But, when it is in the default directory ("My Documents" for me), then it will only save to the default directory. I need to save to a network drive. Is there a way to do this without me going to the "open" a new file button to switch out of the default directory?
I'm experimenting a bit with this code. The idea is the following:
I've got one spreadsheet (ThisWorkbook) were I define 5 names for 5 worksheets in all files of a specific folder (c: emp). I get stuck at this line: "wb.Sheet2.Name = myval2", since I'm for some reason not able to activate the newly opened workbook and change it's name....
Sub wd_testing()
Dim I As Long Dim wb As Workbook Dim firstrow As Long Dim sht As Worksheet Dim cell As Object Dim count As Integer Dim myval2 As Variant Dim myval3 As Variant Dim myval4 As Variant Dim myval5 As Variant Dim myval6 As Variant Application.ScreenUpdating = False
It's important to mention that there is no name conflict and the names work when entered manually.
I've created a macro which copies the current tab to a new workbook (Book X):
[Code]....
I then manipulate the copied data in Book X. Once this is done I move the manipulated sheet back into original file
[Code] .......
The problem i'm having is I'd like to close the newly created Workbook X file once the macro has run but Workbook X is usually called Book2, Book4, Book7, Book32 etc.
Workbook X will always be the previous file if i use the ALT TAB shortcut.
I've created an add-in that runs a simple macro. The problem I have is that when I run the add-in it opens the workbook I originally created it from - is this what I should expect it to do? How do I stop this from happening?
Also, do I need to have the workbook from which I created the add in located in the same place on every machine I want to use the add in on? At the moment if I move the original workbook the add-in won't work.
Trying to create a new workbook from another open workbook, then copying all the sheets that aren't called "Summary" to that new open workbook and then saving it. I get a subscript error on this line:
I have the following code that creates a new workbook and names it after the value of a cell in another workbook. Another part of the macro will switch back and forth between the original workbook and the newly created workbook.
What is the best way to refer to new workbook? I'm familiar with the "workbooks "VARIABLE NAME".Activate" style but, the name of the new workbook will change every time the macro runs and I'm not sure how to refer to it.
the code below.
HTML Code: Sub MakeNewBook() Dim wB As Workbook Dim nPath As String
I have created a spreadsheet that I wish to save as a template. However, when the a new workbook is created from the template it needs to be saved as a Macro Enabled workbook not just a workbook which is the default. To achieve this I added the line 'thisworkbook.FileFormat=xlOpenXMLWorkbookMacroEnabled' to the 'beforesave' macro for the workbook. This works fine except that it makes saving the file as a template quite difficult.
How I can trap the first time a workbook created from a template using New is saved would be most useful.
I am having trouble getting a copy of current workbook to save (with a hopefully unique name) into a vba created folder. The folder creates fine on any drive that I have access to, but the workbook never turns up. The code is only an extract from the whole but it still fails in isolation.
Sub Macro1() Copyit: Dim fso Dim fol As String Dim flag As String fol = "E:Excelb4macrobackups" ' change to match the folder path Ans5 = MsgBox("Create Backup of " & ActiveWorkbook.Name & "?" & vbCrLf & vbCrLf & " Backup File Path:" & vbCrLf & vbCrLf & fol, vbYesNoCancel + vbExclamation) If Ans5 = vbNo Then Exit Sub If Ans5 = vbCancel Then MsgBox "Procedure Terminated!", vbExclamation: Exit Sub.........
i have a workbook blank template for my colleagues to fill in, they fill in this blank template and save it under the serial number of the item they are creating. However a lot of errors exist when they input the serial number inside the workbook where the serial number is a duplicate of a former serial number.
Anyhow i was wondering is there any way when they input the serial number into the worksheet that i could get it to save in a separate workbook and then have conditional formatting to check those serial numbers in the workbook to see if they match?
I have a Workbook that is located in a Networked Folder and is used by several people every day. The Workbook has a lot of VBA and also has links to other workbooks. I am noticing that over time there are several extra files being created from this excel workbook, in the same folder. The Workbook is the only file in this folder. They are not associated with any program and are just a File Type. They are titled a series of 8 random Letters and Numbers and range is size from 700 KB to about 1 MB (Slightly smaller then the Workbook file size).
Also, Is possible to automatically delete these files when they are not needed? or better yet is there some way to Prevent these files from being created in the first place?
I have managed to get my workbook to save with a filename based on two textboxes. I am not sure, however, how to define the directory. I have tried adding a ("mydirectory") on the saveas line but it does not work.
This is my Private Sub CommandButton2_Click() Dim wb As Workbook Set wb = ActiveWorkbook Dim strText As String strText = txtLMSRef.Text & "," & txtPartial.Text wb.SaveAs Filename:=strText wb.Close Set wb = Nothing
I am creating 4 Sheets from a Main Sheet by Filtering Data based on different values in a fixed column, then the Filtered Rows are automatically pasted in the respective sheets. Then these 4 Sheets are creating another file.
The same thing done manually by Grouping the 4 SHeets and then Move Copy into a New workbook also makes the file heavier.
Everything works fine however though the data is not much the file is very heavy, so what do i do to make it of appropriate size ?
Using Dropbox, a lot of people will fill in formulas in personal workbooks from using data from another, central workbook. Since I cannot control where they install Dropbox or where they keep their personal workbooks, I must account for that in functions.
Now, my idea is to make them define the directory of the source in their personal workbook in a specific cell and then using that as a basis for the rest of the functions.
Example
Cell A1: C:Usersuser1Dropboxfolder (copy paste from path in Windows Explorer)
Cell B1: A1&[CentralWorkbook.xlsx]SheetName'!$H$1
Basically I want the unknowing user to copy-paste the path of the central workbook into a specific cell in their own workbook and then build my functions bsed on that. How can this be done?
I want to use the following kill command to delete all files in a folder:
Kill "C:dsmanagerest*.*"
However, I want the directory to be specified not within the code, but within a cell on a worksheet. Ie. Cell A1 would contain the directory C:dsmanager est*.*"
I am trying to find code that locates a workbook (file) in a specific directory, based on a keyword and stores the workbook location in a string to be opened later.
For example, find a workbook containing the word "ancaster" in it's file name (actual file name is "ancaster_summary_2009") in file path:
"C:My Documents" and store the filename and path in a string called "ancasterBook"
I am continuing to struggle with my first attempt at a macro, and wonder if someone would mind taking a look to see where I have gone wrong? All I am trying to do is create file copying tool where the user can define the source and destination directory in workbook cells, and assign the macro to a button to complete the copy of all files from source to destination.
The macros do this:
Source and Location directory defined in Sub Archive1. These are passed to file copy macro Sub ArchiveScript. This macro checks for presence of destination directory, ensures that the directory backslash is in place, specfies the variables fn and fn2 to make sure the filecopy command copies all files in the directory, and then carries out the filecopy function itself.
However, I am getting two errors from the code that I can't figure out (I am still very much a beginner!)
- Invalid procedure call or element on fn = dir() at the bottom
- The copy still works, but only seems to copy one file from the source to the destination, and not all of them.