Get A Module Wide Variable To Provide The Current Filename To The Various Subs

Mar 10, 2009

I am trying to get a module wide variable to provide the current filename to the various subs.

View 2 Replies


ADVERTISEMENT

VBA - Exit All Subs Not Just Current

Sep 10, 2012

VBA - Exit all Subs not just current

View 2 Replies View Related

A Variable Which Is Used By Several Subs In A Worksheet But Is Not Global?

Dec 7, 2008

I am working on a workbook which uses a large number of variables. I am trying to keep them as "local" as possible to keep it simple. Some of my variables are local to the subs they're used in. Some are global as they're used by subs in several sheets. A third type of variable is used by several subs all belonging to the same sheet. Is there a way of declaring them so they're known by all subs in that sheet, but not by every sub in the workbook?

View 4 Replies View Related

Pass Workbook Variable Between Subs

Jul 11, 2007

This is the code after editing to make it more clear

Public Sub 1()
BookA= activeworkbook. name
BookB=Application.Workbooks.Add
Workbook(BookB).activate
End Sub

Public Sub 2()
BookB=Activeworkbook.name

With BookB. sheets(1)
.range("A1")=BookA.sheets(1).range("B1")
End Sub()

At the end of public sub 1, BookB is the active workbook. What I want to do in public sub 2 is to copy some data from BookA to BookB. Unfortunately, when moving from public sub 1 to public sub 2, BookA needs to be defined again. The code above is the code that I use in my add-ins. I figured out for non add-ins code I can define BookA with thisworkbook.name when BookB is active as I before work with BookA. This does not apply for add-ins as thisworkbook will refer to my add-ins code. Is there anyway of keeping definition of BookA is constant from one public sub to another public sub? This is simplified code. In fact, I can't merge public sub 2 with public sub 1 due to some reason which I don't say it here.

View 6 Replies View Related

Extracting Current Worksheet's Filename

Feb 9, 2007

how to extract the current/active worksheet's file's name using VBA code. Let's say I have a an excel file with the name "Test.xls" Which function do I use to return Test (with or without the extension)?

View 4 Replies View Related

Save Word Document With Current Date From Within Module

May 5, 2006

I am using a module to create and save a Word document from an Excel module. I'm using the following line to save the document which works fine but (and this is a big BUT)(to quote a TV programme from long ago) obviously everytime I save the document it will overwrite itself. Is there a way of adding the date it is saved on to the file name so it creates a new document each time.

objWordDoc.SaveAs Filename: = "WAGReport"

I have tried changing it like this but get an error message

Dim dtMyDate As Date
dtMyDate = Format(Date, "DDMMYY")
dtMyDate = Sheets("Client Master").Range("d2")
objWordDoc.SaveAs Filename: = "WAGReport" & dtMyDate

View 3 Replies View Related

Getting Variable Value From Another Sub/Module

Sep 30, 2006

I am writing a Sub2, where I need to extract the value of another variable, which is calculated in some other Sub1. I declared the first Sub1 (where the variable is being calculated) as Public Sub1,

View 3 Replies View Related

Using Variable Filename In VLOOKUP

Mar 26, 2014

I'm working on a project where I need to populate a column with vlookups taken from different workbooks, I have for the most part got it working. However currently, everytime it populates a cell it prompts the user to select the sheet from the workbook as there are two. The sheet name is always the same so I tried to add it into the code so it would avoid having to repeatedly click okay while it populated the table.

This is the original code where it asks for the user to select the sheet every time.

[Code].....

This is what is produced when it is run and the user selects the worksheet each time (which works perfectly fine):

[Code] ...........

I tried to enter the Full Costs sheet name into the code like so:

[Code] ......

However this produces the following:

[Code] .....

The issue I have found is that the square brackets that are around the filename are generated automatically, they aren’t in the actual filename and I haven’t put them in, so I am struggling to work out how to add the sheet name in where it wont be included within the square brackets, as that is what's breaking the lookup.

View 3 Replies View Related

Variable In Filename Reference

Apr 17, 2007

I'm working on a spreadsheet that will access two weeks worth of data at a time. Is it possible to have the filename reference contain a variable or a link to another cell in it?

For example: ...

View 6 Replies View Related

Getting Variable From Module To Userform

Feb 21, 2014

I got some codes defined as below and I want use a userform for and checking the process. If ı could use variable "i " in userform, my codes would work.

Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range

' The variable KeyCells contains the cells that will
' cause an alert when they are changed.

Set KeyCells = Range("E3:P36")

[Code] ......

View 2 Replies View Related

Split String Variable And Use Some In Filename

Mar 16, 2009

I have a filname called ex: "Statusreport xxyyzz.xls"

I'm only interested to put xxyyzz in a variable and reuse it for saving another workbook.

How can I use the different string functions for this. The word "Statusreport" is used for apporx 20 different workbooks.

View 9 Replies View Related

Pass Filename To String Variable

Aug 3, 2006

Have a file lets say is named

sample.xls

Does anyone know how to retrieve the name of the file in VB?

just the name and put it in a string?

View 3 Replies View Related

Define Path & Filename As Variable

Feb 16, 2007

Private Sub cmdImport_Click()
Dim exportFile As String
exportFile = "c:jpmimportTrinity_ImpImport_" & Format( Date, "dd-mm-yy") + "_" + Format(Time, "hh:mm:ss") & ".csv"
Open exportFile For Output As #1

I put a watch on exportFile and it's correctly set to: "c:jpmimportTrinity_ImpImport_15-02-07_17:55:01.csv"

However if I try to run this I get "bad file name or numer" when I open for output - the path exists and I can write to it, so must have a fundamentally wrong approach.

View 2 Replies View Related

Passing A Private Variable To Another Module

Nov 25, 2008

I have some code in which I need to pass the value of "j" from one module to another. "j" is declared in Sheet1 (Data) under the Microsoft Excel Objects.

View 8 Replies View Related

Passing Variable Value From Private Sub To Module

Aug 12, 2009

I am trying to pass a variable called "Filter" from a Private Sub to a Module but keeping coming up with a zero value in the Module. I tried to make the variable Global but that didn't seem to work.

Private Sub Code as follows:

View 3 Replies View Related

Use Input Box Variable In More Than One Module / Procedure?

Apr 10, 2013

i know i have done this before but im totally blanking. I want to user the inputvalue in procedures called from controller, but it just shows as empty.

Code:

Sub controler()
Static inputvalue As Long
inputvalue = InputBox("Please set min size of trades.")
'other macro's called here
end sub

View 4 Replies View Related

Transfer Userform Variable To Module?

Jun 12, 2013

i have a userform where when i initialize i load my combo box with a range

I have a variable which = combo box value

Sub cmd click()
myval = cbo.value
unload me
End sub

How can i use or pass this variable to my standard module i.e

Sub test()
myevent = myval
end sub

View 6 Replies View Related

VBA / How To Use Variable In Userform Declared In Module

Sep 9, 2013

I am trying to use some code similar to what i have used in one of my Modules in a Userform (The module calls this userform)

I have declared a few variables in the module:

Code:
Public LastRow As Long
Public TabLen() As Integer
Public AHUArray() As String
Public ArrayDim As Integer

and i want to try and use them in a userform (i call the userform through an bit of code that usures that the other subs that assign values to the variables have been used so there should be values in the variables??i think?)

i get to this line in my userform

Code:
TabPos = TabPos + TabLen(i)

this is the first line that requires a value to be in the array and it errors: Subscript out of range

I just want a few variable that are used in a module to be available in other modules and userforms.

EDIT:the (i) is decalred in this sub within the userform. A thought occurs, the sub in the userform is a private sub, might that effect it?Also, explain Sub vs Private Sub vs Public Sub?, im new to this! the sub that fils the arrays in the module is just Sub SubName_Click()

View 4 Replies View Related

Save A Module Level Variable

Jul 20, 2006

I would like to save a module level variable but do not know how to do it. I have tried using the public key word. If I put it in the sub, I get an error when it tries to compile the sub. If I put it outside of a sub, it just doesn't work. Surely this is something easy.

View 8 Replies View Related

Module Variable Not Recognized In Userform

Oct 16, 2006

I created in module custom toolbar with a button, see the

Option Explicit
Public ctrlGUI As CommandBarControl
Sub CreateToolbar()
Dim cb As CommandBar
On Error Resume Next
Application.CommandBars("Cust").Delete
On Error Goto 0
Set cb = Application.CommandBars.Add( Name:="Cust", temporary:=True)
With cb
.Visible = True
Set ctrlGUI = .Controls.Add(Type:=msoControlButton, temporary:=True)
With ctrlGUI
.FaceId = 3205
.Style = msoButtonIcon .............

View 5 Replies View Related

Pass Variable To UserForm Module

Dec 28, 2006

I have a macro that when it runs presents a form that gives the user an option to skip the calculations or continue. If they click Skip then it continues the 'Next CE' . My problem is I can't get the Boolean value to pass from the form to the macro. Here is what I have

The main macro

Sub Dividend_MF()
For Each sh In ActiveWorkbook.Worksheets( Array("G&I", "Growth"))
For Each ce In sh. Range("a5:a" & sh.Range("a65536").End(xlUp).Row)
If Not IsEmpty(ce) And Not (IsError(ce.Offset(0, 56))) Then
If ce.Offset(0, 56) = "X" Then

View 9 Replies View Related

Using Manual Filename Variable To Import Data

Aug 18, 2006

referencing a variable during a data import. I have searched the forums here and the web for a couple weeks and attempted enclosing the variable in many different symbols.

Nothing I have tried works. I have also read chip pearsons guide but I was still not able to get it to work.

I am trying to provide a way for the user to input the filename and location in an input box and then use that variable to import the data. It is only one file that is needed.

The message box filename is only included to allow me to verify the text input.

Dim Filename As String

Sheets.Add. Name = "All Data"
Filename = InputBox("Enter Filename: ", "Enter Filename Location")

MsgBox Filename
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;Filename", Destination:=Range("A1"))
.Name = "SHOAlarmsJune2-9"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False

View 3 Replies View Related

Vba Code Which Saves A Workbook With A Variable As The Filename

Jun 25, 2007

I have a VBA form that the user enters information into and once they click submit on the form the code opens a new workbook and then enters the information from the form into that workbook. What I need is for that code to then save the workbook with a filename from one of the fields entered into the form but I'm not too sure how to do this.

View 3 Replies View Related

Call/Run Macro Within Same Module Using Common Variable

Feb 3, 2009

The attached file contains a simplified version of a more complex macro in which a sub routine will be called a number of times to change the colours of cells in different ranges. However, an error is triggered because the a variable and range are not defined in the subroutine although they are in the main part of the macro.

I know I am missing something obvious here, but I'd appreciate any help in knowing how I can define the ranges in the main procedure and then call the subroutine to change values in the different ranges.

View 6 Replies View Related

Dim Current Workbook As Variable

Jul 2, 2014

I have a Macro that opens a closed file to VLookup some info and pull it to my spreadsheet then close that workbook. the problem I have run into is writing the Macro correctly so if I were to change the file name of the workbook I am running the macro with that it will still use the range declared for the workbook. I have colored the file path that I want to dim in Blue so that it will be easier to see what im trying to do. here is my current macro that works perfectly unless I save my current workbook under a different file name...

Sub Button7_Click()

Sheets("Sheet1").Unprotect "Password"

Workbooks.Open Filename:="\NDGI-SPARE-1UsersownerDocuments2014Vom ResultsVomResults.csv"

Dim c As Range

[Code] .....

View 8 Replies View Related

Assigning Current Region To A Variable

Dec 7, 2009

I’m attempting designate the cell which will then determine the start of the current region, to be copied and pasted to another sheet. I’m receiving an “ERROR 1004” , Method Range of object_ Worksheet Failed.

View 4 Replies View Related

Store Current Sheet Name As Variable

Aug 27, 2008

I have a workbook that is composed of forty (or so) worksheets containing data and a single summary worksheet that has command buttons that take the user to the appropriate data worksheet for their specific project. Each data worksheet is exactly the same in terms of where the header row starts, and the specific headings.

On each data worksheet there is a command button that when clicked, builds a pivot table of the data for the current project. I have been able to create VBA code that hides the columns containing the data and then creates the pivot table in the empty (unhidden) columns n the same worksheet. This works fine, but is not a good solution from a useability standpoint.

What I have been trying to do is when the command button is clicked I want to capture the name of the current worksheet as a variable in VBA, go to a separate worksheet to build the pivot table, and when the user clicks a ‘Review Data’ command button on the pivot table worksheet they are taken back to their original worksheet containing their data. Is this possible?

View 8 Replies View Related

Replace Filename With Variable In "Activecell.FormulaR1C1=" Expression

Feb 27, 2009

Replace filename with variable in "Activecell.FormulaR1C1=" expression
I have recorded a macro which contains several lines of code like this one:

View 2 Replies View Related

Windows ("variable Filename").activate

May 26, 2009

I have created a macro to split out information from one excel workbook into 2 additional workbooks, and format them the way we need. Everything works fine on the filename I originally recorded the macro from, but is giving me a 'subscript out of range' error when trying to run the macro on a file with a different name.

currently, my test file has the 2 following fields that I somehow need to have as variables:

Windows("insmacrotest20090418.xls").Activate

and

Windows("Book1").Activate

I need the filenames and workbooks in the parenthesis to be variable so that the macro can be run on other reports with varying filenames.

View 10 Replies View Related

Keeping Track Of Which Macro Is In Which Module Since You Can't Rename The Module?

Mar 27, 2009

After all the awesome macros I've obtained with the help of all of you, I now have over 30 macros, each in its own module. I have tried without success to re-name the modules with no luck. How is everyone organizing these?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved