I have an Excel sheet with a long list of data. A short example is shown below:
Section | Title | Item 1 | INTRODUCTION | a 1.1 | title2 | b 1.2 | title3 | c 1.2.1 | title4 | d 1.2.2 | title5 | e
I made a VBA macro in Excel that runs through this list and creates a new Word file for each item. The filename of the document is based on the data in the Excel file (section and title). Now I would like to add a custom property to each of the newly created Word files, i.e. the value in the 'item' column. Does anyone of you know how I should do this? Or should it be better if I write a macro in Word that runs through the Excel data to create the word files? Here is the code I use to generate the word files:
I'm trying to use the Date Time Picker control as a time picker and only want hours and minutes to show. Can this be done with its custom format property (Example)? The usual number formatting string doesn't seem to work.
I made a new class to make other code less redundant, but it isn't functioning. The class has a "workbook" and "worksheet" member, and these can be accessed through properties. The problem is that the properties don't actually seem to return anything, and no data can be accessed through them.
Private mActiveWorkBook As WorkBook Private mActiveWorkSheet As Worksheet
Property Get wSheet() As Worksheet wSheet = mActiveWorkSheet End Property
Property Get wBook() As WorkBook wBook = mActiveWorkBook End Property
'Sets active WorkBook Sub SetActiveWorkBook(ByVal wBook As String) Set mActiveWorkBook = Workbooks(wBook) End Sub
'Sets the activeWorksheet in the workbook. Sub SetActiveWorkSheet(ByVal wSheet As String) If mActiveWorkBook Is Nothing Then MsgBox ("Invalid WorkSheet selection - WorkBook not defined") Return End If
Set mActiveWorkSheet = mActiveWorkBook.Worksheets(wSheet) End Sub
uDate.wSheet. Range("A1").Value = "foo" ' Expected result - set Cell A1 in sheet testTab = "foo" ' Actual Result - nothing
Dim st As String st = uDate.wSheet.Range("B5").Value MsgBox (st) ' Expected results - bring msgBox of values of cell B5, this cell is not empty ' Actual Result - Empty Message box comes up
So - its fairly obvious to me that something is wrong with the properties. The members themselves are not null, I have verified in the debugger that the class members refer to actual sheets/workbooks, but the properties don't like passing anything out and show as "variable not set" in the debugger. How can I get this to work?? It works fine when I do not use the class, like such:
Dim wB As WorkBook Set wB = Workbooks("Book1.xls")
Dim wS As Worksheet Set wS = Worksheets("TestTab")
Dim st As String st = wS.Range("B5").Value msgBox(st)
But I would like to get the class and properties to work to save clutter elsewhere.
I am having problems with some vba codes when I protect my workbook; 'I get an run-time error 1004 Unable to set visible property of the worksheet class'
I have a form with several combo boxes, and they function just the way I like as far as being able to pick from the list, or typing in them and having it show you the next available item in the list as you add letters. Whats happening that I would like to know how to deal with is... as soon as you type a letter that is not in my lookup range it generates an error. "Could not get the list property - Invalid property array index". I don't want people to be able to add to the list, but I would like a msgbox to pop up. Then allow them to go back to the box and try again.
There was an article in ozgrid new about excel custom toolbars (<<hover over). The article addressed making the custom menu option available in one workbook with Private Sub Worksheet modules as follows
Private Sub Worksheet_Activate() Application.CommandBars("Worksheet Menu Bar").Controls _ ("My Menu").Enabled = True End Sub
Private Sub Worksheet_Deactivate() Application.CommandBars("Worksheet Menu Bar").Controls _ ("My Menu").Enabled = False End Sub
How do you get the first module to run apon opening the workbook and the second module to run when you close the workbook.
I have created a workbook and made a custom toolbar to perform the macro functions for the sheets in the workbook. Everything works great for me, but I want to attach the custom toolbar to the workbook so that whenever someone else pulls up the workbook they pull up the custom toolbar too.
I used the tools menu, clicked customize, toolbars, attach, selected the custom toolbar and clicked copy.
No toolbar appears.
I can select View, Toolbars, and select the custom toolbar, then the toolbar appears, but when I close the sheet the toolbar remains.
When someone else opens the sheet, the toolbar appears without any "buttons." It is an empty toolbar.
The help text isn't helping because the instructions for attaching a custom toolbar to a worksheet (tools/customize/toolbars/attach/copy) do not attach the toolbar to the workbook.
How can I have a custom defined workbook run a particular macro?
I'm using the Run Application Method:
Application.Run("'Workbook.xls'!Macro")
However the workbook.xls field is static as my program loops through a folder containing various workbooks, opening these workbooks, and running a specific macro housed in their specific module.
Dim MyFile as Object MyFile = Dir("C:Test") While MyFile ""
Workbooks.open Filename:="C:Test" & MyFile Application.Run("'Workbook.xls'!Macro") MyFile = Dir
How can I define the current active workbook in the run method? Using the custom 'MyFile' in place of the workbook does not work.
I'm trying to load a custom menu in a workbook to avoid having users to load an add in to use the spreadsheet. I'm trying to add this to the "this workbook" tab but I've never done this.
I have downloaded a custom menu workbook attached. I am wanting to only show the custom menu in one workbook as it appears in all workbooks open at the time.
Using example code from Adding Custom Menus, I now have functional menu items that call my macros appropriately. The example also contains code to add or remove a menu conditional on its window being active. What I need is a slight variant on this but not quite obvious to my novice brain.
The add and remove menu code is now stored in my personal.xls file. However, I need that the condition check that a key string be present in the name of the active window, not the file where the macro is stored.
Thus, if the front window is of the file named MyData, then the special menus get added (the conditional string is "MyData"). If the window is named YourData, the special menus get removed. Note, neither of these two files contain any macros.
I am building a macro and am just not figuring out how to do this. I am trying to create a new workbook, then give it a name. Simple right? Well, I have the format for the file name to be "mm-dd-yy Transmittal #.xlsx" but I can't figure out how to make the # part of that equation start as 1 but if the file already exists change it to 2, if that exists, change it to 3, and so on. Here's what I have so far:
Code: Sub Transmittal() Dim NewBook As Workbook Dim MyPath As String
[Code]....
I don't think I'm allowed to do "x + 1" so that is probably where my problem is coming from.
I want to create a custom tool bar for a work book but when I right click in the unused part of the tool bar area the only options I get are customize Quick access tool bar and customize the ribbon.
I created 3 custom toolbars. I want toolbar A to be visible only in Workbook A.xls, toolbar B to be visible only in Workbook B.xls and toolbar C to be visible only in Workbook C.xls. while Workbooks A,B, and C are open at the same time. I use Workbook A to automatically open Workbooks B and C.
Problem: Since I'm openning the Workbooks automatically it only keeps the Toolbar C visible on all Woksheets.
I included the following code in the This Workbook Object on each Workbook:
I had made a Workbook with my own command Bars, and everthing is ok .. the problem is when i copy it to anthor pc. i have got an error msg. and when i check the code (debug) i've found the problem is with that command bars ( it's missing ) and now the Q is:
how to copy a workbook with it's all add-in's and customised bars ?
The following code for a custom menu is used in a workbook which has two sheets with embedded charts, two chart sheets and several sheets for calculations and information
In This Workbook
Private Sub Workbook_Activate() 'Changed Activate to Open Run "AddMenus" End Sub
and
Private Sub Workbook_Deactivate() 'Changed Deactivate to Close Run "DeleteMenu" End Sub
and
Private Sub Workbook_BeforeClose(Cancel As Boolean) Run "DeleteMenu" End Sub
Is there any way to filter/sort a workbook by a specific text. (EX. Unit 17) I have a spread sheet with 40,000 plus rows and in 1 column it has descriptions. I am needing the filter to filter out all occurrences of Unit 17 and Unit 16. They will not always say the something happened to them. EX Repair brakes on Unit 17 or maybe repair tires on Unit 17...
I am working on building a custom menu and I am looking for the code that would open a specific workbook execute a macro when I select the tab, can this be done????
I cannot figure out how to get my error handler to work, or actually, not work. It seems to work fine when there is an error, but the code still gets read even when there was not an error. Basically, I am trying to open a file, which may or may not be there. When it is not there I want a message to pop up informing the user. However, when the file is there and it opens, the error handler still gives the message box. Any ideas what I am doing wrong?
Private Sub btnOK_Click() Application. ScreenUpdating = False Dim LCSfile As String LCSfile = frmSelectFile.Listbox1.Value On Error Goto ErrHandler Workbooks.Open Filename:=sPath & sDate & "" & LCSfile & "QUANT.CSV" ErrHandler: MsgBox ("File is not quantitated. Please select another file.") Application.ScreenUpdating = True
I'm a fan of the Excel 2010 table styles, but can't figure one thing out. When I create a table in excel (Ctrl+T), I like to reformat it with a new defined style. When I save the style, I can use it while I'm in that instance of excel, but when I close and reopen excel, the style is gone. How to save the custom formats to they are always available?
Having problems with trying to get my vba code to access the SpecialCells property. Receiving the following error.... Unable to get the SpecialCells property of the Range class. The section of my code is below that is causing the error. Keeps stopping on the "Selection.SpecialCells(xlsCellTypeVisible).Select" line.
Sheets(" Book Query").Range("A6:I6").Select Sheets("Book Query").Range(Selection, Selection.End(xlDown)).Select Selection.SpecialCells(xlsCellTypeVisible).Select Selection.Copy Sheets("Inventories and Variances").Select Sheets("Inventories and Variances").Range("A7").Select
I'm trying to make a converter between about 8 various types of values. These are not units like Km or miles or something like that, but rather numbers that represent a specific "hardness value" on a variety of scales (to name a few: HRC, HRA, K)
What I've been doing so far is plotting the two types against eachother and then getting the best trendline I can so that I can use that formula to convert between the two with relative certainty. (for example, when plotting HV vs HRC my fourth order polynomial trendline with an Rsquared of 1 is y=0.0001x4 - 0.0188x3 + 1.0768x2 - 20.709x + 350.69)
My questions comes up where I was hoping to make a window or box of some sort allowing the user to input a numeric value, then selecting the Input units and the hopeful output calculated units, and have the box spit back to the user the conversion.
I want to be able to create a range of VBA userforms to quickly perform long tedious tasks. I want these userforms to be accessed from a nice tidy toolbar.
I have done this and it looks nice and works well. What I would like to be able to do is have my custom toolbar of userform controlled functions be transferable so that if someone else wants my toolbar and attached functions they can install it easily much the same way you can do with an add in.
Is this sort of thing possible or does it require them to manually install all my userforms, modules and toolbar? If it is possible what sort of things should I be looking at?
I would like to Copy the cell value from A1 into the next available empty cell in a column (in this case sheet2 A) so that I can create a list of values from A1 over time and graph it.
Sub test() With Worksheets("BUDGET") .Range("E10").EntireRow.WrapText = True With .Range("B10").CurrentRegion With Intersect(Worksheets("BUDGET").Rows("10:" & Rows.Count), .Cells).Borders .LineStyle = xlSolid .Weight = 1 End With End With End With End Sub This code works fine on my Laptop (2007). On Desktop (2003), gives error: Unable to set the LineStyle property of the Borders class
.LineStyle = xlSolid highlited
I have tried this (on both computers) in a larger procedure(where it should be) and in a Module of it's own. Same results.
a macro that steps through the list of files found during a search and displays the path for each file.
With Application.FileSearch For i = 1 To .FoundFiles.Count MsgBox .FoundFiles(i) Next I End With
how can i modify this macro so that it displays only the file name not the full path for example instead of displaying "C:Documents and SettingsDesktopMainstatment1.txt" i want it to display "statment1.txt"