Pass Chosen File & Path To Variable
Dec 1, 2006
I am running a macro which ends up showing the save as dialog box. The name is correct (data) and the type is correct (XML files) but no matter what I try the file path is not right. Here is the section of
sDataFile = Application.GetSaveAsFilename("data.xml", fileFilter:="XML Files (*.xml), *.xml")
Set fs = CreateObject("Scripting.FileSystemObject")
Set js = fs.CreateTextFile(sDataFile, True, False)
Set f = fs.GetFile(sDataFile)
sFilePath = f.parentfolder & ""
Set f = Nothing
How do I set the file path? I have already seen lots of answers to this but they are based on changing the path permanently or on there being no dialog box already open. I need total automation with the user not being able to see any of the save process.
View 3 Replies
ADVERTISEMENT
Jan 18, 2012
How to pass data from userform to excel sheet using file path?
View 4 Replies
View Related
Aug 8, 2008
I am calling a sub that I want to do a SaveCopyAs using a variable as the file name but can't get it to work. The file name displays properly in a message box but when I do a SaveCopyAs it does nothing.
This code works:
View 9 Replies
View Related
Jun 25, 2014
How could i get the below code to work with a variable as the file name?
Or could I use something like "thisfile" to determine where to import to.
[Code] .....
View 5 Replies
View Related
Aug 20, 2007
I am having a problem reading from a file. I am working with some old code. I am reading information in from a txt file. The information on the txt file is separated by commas on each line. My question is, how can I read in for example, the third section on the first line. By section I mean...
line 1:
section1, section2, section3, section4, section5
I want to read section3 into a string variable. If anyone can help me please post. I am having the hardest time finding this online.
View 9 Replies
View Related
Nov 21, 2008
If I have a file open called test file, How I can find the file path of the file that is open and how can I store that's as a variable?
What I am doing is trying to open a file that excel closes in a save as process!
View 9 Replies
View Related
Feb 27, 2008
1 I need to open a csv file in order to use data in it at location "C:BarkingEMCIN" to input into an xls spreadsheet. I then need to use the info from the xls spreadsheet along with other info input by users to produce another .csv and it be deposited at "C:BarkingEMCOUT"
The name of the file at "C:BarkingEMCIN" will change everyday or even multiple times a day and be in the format "AVA_DA_260208_BPL_EDF_001.CSV" "AVA DA " will remain the same "260208" will be todays date the next 2 will be interchangeable depending on requirements and use BPL EDF and SSE will be interchangeable depending on requirements and 001 will be the version whcih will be changable. _ underscores will be used as seperators
They will then be save in the format "NOM_DA_260208_BPL_EDF_001.CSV" using the same prinipals as before but automatically saving as the next available when needed with a prompt to tell the user what it will be
View 5 Replies
View Related
Jan 29, 2009
I am looking for macro that when run, will open a file explorer window and prompt the user to select a folder and file where they have data stored. Then I need it to be stored as a variable and used as a part of a "Workbook.Open Filename" command.
The reason for this is that, I have a huge formatting marco stored within a workbook. When a user extracts a report from SAP, I want the workbook to grab the file that is extracted, open it and import all of the data in order to be formatted.
View 6 Replies
View Related
Oct 5, 2007
I use the code below to enter a value from a list box in a cell on a workssheet. Is it possible to code VBA to enter a number for the position of the selection in the listbox to a cell in a worksheet rather that the actual value from the list box. For example if my list is:
Option1
Option2
Option3
And I click on Option2 in the list, I can sennd the value 2 to a cell on the worksheet rather that the value "Option2' from the list.
Private Sub ListBox1_Click()
Sheets("SA").Range("SA_Poistion_To_Archive_A_New").Value = ListBox1
End Sub
View 2 Replies
View Related
Mar 4, 2013
is it possible to configure Excel in order to save the Hyperlink path for a file with absolute path and non relative?
I notice that the hyperlink is ....pdf ry.pdf
if I change the position of the file excel there is a problem!
I would like to save es. d:invoichepdf ry.pdf
View 1 Replies
View Related
Sep 27, 2006
I have a variable ("DestFile") that defines a path to a file (used in saving the file)...
I'm in the process of getting a Sub to hyperlink to this file, but in some circumstances, I may only want to hyperlink to the folder, not the actual file...
How would I go about trimming the "DestFile" address to get a "DestFldr" address?...
An example of "DestFile" might be;
S:BryanFor KenGulf ConstructionST0609014-t.xls
(the file name length may vary)
What code can I use to consistently trim it back to;
S:BryanFor KenGulf Construction
as the "DestFldr" variable?
View 4 Replies
View Related
Oct 3, 2012
I want to run a macro to separate File Name and Path from the given complete path
For Example
Code:
In Column A : Given Complete Path " C:MainFolderRecordsSubFilesFile1Record.pdf
I need it separeted like
Code:
In Column B :File Name = Record.pdf
In Column C :File Path = C:MainFolderRecordsSubFilesFile1
Is there any way to do this through a macro
View 2 Replies
View Related
Jan 26, 2007
The first goes through a directory and opens all the files.. after it opens a given file it goes off into a sub-routine to process the data in that file.
I am trying to create a counter in the first sub-routine and then pass that value into the second sub-routine to tell it to put the values out on the next row down.. so the first time through it puts the values out on row 1, next time it puts them out on row 2, etc.
View 9 Replies
View Related
Oct 20, 2005
I have code in a userform that shows another userform with a text box. When the user types text there and presses OK, I want that userform to close (which it does fine), and return back to the original userform (which it does fine), but I want the typed text to be stored in a variable that the code in the original userform can use.
I tried declaring a public variable, "Rresponse1", in each userform's procedure, but that doesn't work. I test for the content of the variable afterward in the original userform and it is empty.
In the original userform I have:
SaveList.Show '(this is the second userform)
MsgBox "This is response1: " & Response1 '(to test if the variable is being passed)
In the userform SaveList, in the Private Sub CommandButton1_Click() procedure, I have:
Response1 = SaveList.ListName.Text
Application.ScreenUpdating = True
MsgBox Response1 '(to test the variable, here it shows the text fine)
Unload SaveList
How do I get the Response1 variable to keep its content when control is passed back to the original userform?
View 6 Replies
View Related
Jul 25, 2008
I want to work on a range
range("A1:B100")
The number 100 (in B100) comes from another varibale M
Now how do I write the range so that I don't have to write 100. I want to pass on the variable in the range.
the code should look somewhat like
Range("A1:BM").
I don't know how to pass this variable M onto the range.
View 30 Replies
View Related
Nov 6, 2008
It is possible to define a variable in a MS Word macro and send it to an Excel spreadsheet?
View 9 Replies
View Related
Dec 11, 2009
I created the following sub to signal when a macro in Module 1 is complete:
Public Sub Done()
Dim complete As Boolean
complete = True
End Sub
I placed this just before the end sub in the macro for which I am trying to detect that it has finished executing:
Call Done
End Sub
In the Sheet 1 Module, the code fails at the statement:
If complete = True Then
The error returned is "Variable not defined." All three subs are declared as Public. Why does the Sheet1 sub not recognize the variable "complete" from the Module 1 macro?
View 9 Replies
View Related
Mar 20, 2014
I want to open a specific sheet and refresh only said sheet when i open another sheet for example x.xls
So opening x.xls will automatically open y.xls
I've tried this in the workbook code area but it doesn't do anything.
[Code] .....
View 1 Replies
View Related
May 24, 2014
I am trying to pass two variables RARD and CARD from Sheet1 'change selection' subroutine to the 'Set ARD Command button click' subroutine. The variable value remain empty and it gives me a 1004 error when I try to execute this line of code:
[Code] ....
What I am trying to do is put the text value 'ARD' in the cell on sheet1 which was the original cell I clicked on to open the userform2. To do this I click on the 'Set ARD' button on the userform2 which is then suppose to hide the userform2 and put the 'ARD' text in the selected cell on Sheet1.
I have attached the workbook for review : Therapy Tracker - Tester V2.10 - deleted logo.xlsm
View 1 Replies
View Related
Mar 15, 2012
is it possible to assign the formula to a variable ? here i am trying to get only the filename excluding the path and assign it to a string variable. but its not working check "strr1" line.
Sub TestReadDataFromWorkbook()
' fills data from a closed workbook in at the active cell
Dim tArray As Variant, r As Long, c As Long
Dim i As Integer
[Code]....
View 5 Replies
View Related
Sep 26, 2013
How do you pass a variable value in Visual Basic?
I have a variable called LastRow
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Would like to pass the value in my Do While loop
Option Explicit
Sub IncValue()
Dim MyCell As Range
Dim LastRow As Long
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
Do While MyCell
View 2 Replies
View Related
Jun 8, 2009
I have a spreadsheet with about 30 charts on it that I would like to attach a macro to which opens the chart in a form. I've figured out how to do this last part, but am stuck on how to pass a variable to the form code which tells excel which chart to copy. Essentially what I'm doing creating a macro for each chart which would run when that chart is clicked on. This macro is identical for each chart except for the name of the chart being passed.
Sub Chart1_click()
ShowChart "Chart 1"
End Sub
Sub ShowChart(c As String)
frmChart.Show
End Sub
In the UserForm_Initialize code located in the userform module, I'd like to call the code which saves and loads the image of the clicked on chart. But here's where I'm stuck. How do I pass c to the code in the form module...e.g, how to pass c to UserForm_Intialize and to ChartZoom? Here's what I have so far...
Private Sub UserForm_Initialize(c As String)
ChartZoom c
End Sub
Private Sub ChartZoom(c As String)
frmChart.Show
Dim Cht As Chart
Set Cht = ActiveSheet.ChartObjects(c).chart
Dim CName As String
CName = ThisWorkbook.Path & "cht.gif"
Cht.Export Filename:=CName, FilterName:="GIF"
imgCht.PictureSizeMode = fmPictureSizeModeZoom
imgCht.Picture = LoadPicture(CName)
End Sub
View 9 Replies
View Related
Aug 15, 2008
Following statement works for me:
bdcTerm1 = ThisWorkbook. Sheets("ws2"). Range("A1").Value
But instead I want to parse through 50 rows and dynamically get the value instead of using a static Range("A1"). So I am trying to do the following:
For Row = 1 To bdc_rows
bdcTerm1 = ThisWorkbook.Sheets("ws2").Cell(Row, 1).Value
bdcTerm2 = ThisWorkbook.Sheets("ws2").Cell(Row, 2).Value
Next Row
But I get errror.
View 5 Replies
View Related
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
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
Jan 18, 2007
I have a code below which need some input from user. This input will also be serve as the input of the subroutine which i am going to call. However, i do not know how to go assign this input to the subrountine which i will be calling, can anybody help ?
For example, the "input" variable will also be served as an input in subroutine test2 ...
View 6 Replies
View Related
Jun 11, 2007
I have a macro that nicely select the named range that the active cell is in. I want to chain on to that macro a macro that has a parameter a range with that active selection. I dont see how to "take" the active selection on the worksheet from within the macro and pass it to another. I assume I could change the cellInRange macro to return a range, however I dont yet see how to do that.
View 2 Replies
View Related
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
Jul 26, 2007
I have come up with the following formula to pull sums of data by month. I am using this because it is inconvenient to use the DSUM formula (I can't put all the criteria together in a simple way):
{=SUM(IF('Sheet1'!$B$2:$B$20="Person1",IF( DATE(YEAR('Sheet1'!$A$2:$A$20),MONTH('Sheet1'!$A$2:$A$20)+1,)=C2,'Sheet1'!$D$2:$D$20,0),0))}
I would like to, in a macro, assign a variable to this result - but cannot figure out the VBA code for it.
View 5 Replies
View Related
Aug 12, 2007
This line in my code is causing an invalid qualifer error message:
lngNew = wsNew. Range("B65536").End(xlUp).Row.Offset(1, 0)
Option Explicit
Sub Disney_DumpData()
Dim wbBook As Workbook
Dim wbNew As Workbook
Dim ws As Worksheet
Dim wsNew As Worksheet
Dim rng As Range
Dim rngNew As Range
Dim rngUnit As Range
Dim rngUnitPaste As Range
Dim lngNew As Long
Dim Cnt As Integer
Application. ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.DisplayAlerts = False
Set wbBook = ThisWorkbook
Cnt = 0
'Dump To New File
'/Define new workbook
Set wbNew = Application.Workbooks.Add.....................
View 7 Replies
View Related