Test Whether Or Not An External File Exists?
Sep 15, 2009Is there a way to test (from Excel 2002) whether a specified file (not necessarily an Excel file) exists on my computer? I could specify the complete path.
View 4 RepliesIs there a way to test (from Excel 2002) whether a specified file (not necessarily an Excel file) exists on my computer? I could specify the complete path.
View 4 Repliesis there a way to test if a list exists on a sheet? I'd like to do something like this:
View 2 Replies View RelatedAfter going though the archives, I could not find how to test for an entry that does not have a sheet to be pasted into. I have a series of worksheets with the month-year for tab labels. The format for these tab labels is ("mmm-yy"). My code will place the new entry into the first available row of the sheet with the same month-year as the entry. I can enter any item with any date in any order and as long as there is a sheet with the same month-year, the entry will be placed into the correct sheet. Temporarily, when I need to add a new month, I click on a CommandButton that uses this code (located in a general module) to make the new sheet:
Public Sub AddNextSheet() ...
How to see if a SeriesCollection that has been named exists so when the corresponding toggle button it clicked it turns on or off the correct corresponding dataseries.
When I create a series I use something like:
[Code] ............
Where the range "tblJim[Quizes]" contains the quiz scores which are the data series pointes and "=Data!$C$6:$C$35" has the respective dates.
When that toggle button is clicked I need to test if the SeriesCollection "Jim" exists so if it does I can delete it and if not, create it.
Also, as much as I hate to multi-subject but usually do anyway, I am wondering if there is good example of doing the same ends by a different strategy - a chart with everyone on it and by applying data filters to the dataset I would turn on and off people's data.
I want to check if a worksheet exist, and if it does I want to skip the part of a macro that creates it, else I want to create it.
Here's what I have so far:
Got most of this code from the web and I can't get it to work. The part I added was the array and loop bit. As a test I specifically renamed one of the sheets in the file to be something NOT in the array, but it still goes through like it exists (I.e. shexist=True). What did I miss?
Dim wsname As String, shexist As Boolean
myarray = Array("Statement of Values", "Vehicle", "Driver Info.", "Revenues by Discipline", "Revenues Geographically", "Employee-Payroll Info. CDN & US", "U.S. Payroll", "Employee-Payroll Info. FOREIGN")
For i = 0 To WorksheetFunction.CountA(myarray) - 1
shexist = False
On Error Resume Next
wsname = myarray(i)
shexist = CBool(Len(ActiveWorkbook.Sheets.Item(wsname).Name))
On Error GoTo 0
If shexist = False Then
MsgBox "The worksheet '" & wsname & "' does not exist in this file or has been renamed." & _
vbCr & "Please check the file and try again.", vbExclamation, "Consolidate"
GoTo THEEND
End If
Next i
Is there a way to check if a named range exists before I run a piece of code? I created a new file that has need for all the old file's ranges plus a couple more, and I want to use the same macro for both. So on the first file I just want to say, if these other named ranges are there, go ahead and do his other thing.
View 6 Replies View RelatedI'm creating a macro to select, modify dimensions and place shapes on a excel sheet. (I'm talking about pictures insered and stocked in a specific sheet of my workbook)
When the users insert a new picture he has to set a name for each of them.
A combobox contain the choices, when an item is selected, the macro identify, size and place the corresponding picture.
But I have a bug if a shape doesn't exist when I try to select it :
Sheets("fiche de controle").Select
'select the sheet with the pictures
ActiveSheet.Shapes(Item_old).Select
'select the shapes "Item_Old"
Item_Old is a variable corresponding to the picture name.
If the user made a typo, I have a bug.
Someone knows how to test if the shapes exist to display a meesage if not ?
Or somethig to avoid this kind of bug ?
How can I test in my VBA wether a named range (with a scope of sheet) exists on the active sheet?
Code:
If "EmployeeEmail" exists on the active sheet Then,
xxxx
Else
yyyy
End If
Using Excel 2010.
I have attached the file I am working on. I am attempting to create a link to an external file based on the value of cells in column A. Then I would like to simply copy the formula down, lets say in Column B, the rows and as I do the external file reference will change depending on the value within the cell in Column A. I hope that I am making sense.
I am using Windows Vista with Excel 2007. The files will all be within the same file folder, however, there are hundereds of files so I won't be able to open them all for the indirect to work.
I have a file that gives some statistical data to my co-workers every 15 minutes. A common question I get is "How does that compare to last week?" Then I have to open the file from 7 days ago, find the data from the same time interval, and subtract it from this week's number in my head. I'd like to have excel do this for me.
I know how to get data from an external file. The problem is, these files are named with a date on the end of the file name. So tomorrow, the static formula won't work anymore (or rather, it will give data for a file from 8 days ago, instead of 7). I'd like to excel to use today's date, find the file from 7 days ago, and get the data from that file to compare to the current file.
Here's what I've done so far:
Code:
ThisDate = Range("C1").Value 'the cell with todays date in it
ThisDateName = Format$(ThisDate, "yyyy-mm-dd") 'now formatted the way I need it
ThisDate7 = Range("G1").Value 'the cell with the date 7 days ago
ThisDateName7 = Format$(ThisDate, "yyyy-mm-dd") 'formatted correctly
ThisDate14 = Range("G2").Value 'the cell with the date 14 days ago
ThisDateName14 = Format$(ThisDate, "yyyy-mm-dd") 'you know, in case of a holiday 7 days ago
I have no clue what to do next. I want Excel to: Use "ThisDateName7" to find the file with the name "pph_tracker_[ThisDateName7].xlsm"Get data from a cell in that file (say, C15)Subtract it from the data in the same cell (C15) in today's file (this week - last week)Give me the result in today's file (say in cell C20)Do that again for cells D15, E15, and so on (result in D20, E20, etc)
I assume I can figure out the rest from there. Can I use the variable names in an actual formula in cell C20? Something like:
=C15 - '[pph_tracker_{ThisDateName7}.xlsm]Sheet1'!C15
or even
=C15 - '[pph_tracker_{The Date in Cell $G$1}.xlsm]Sheet1'!C15
which would require no macros at all!
I've got a couple of formulas in a workbook which lookup values in another workbook. When I reopen the initial workbook the formulas results come back as errors (i.e. #VALUE!) unless the workbook it is looking at is also open. This is not desirable, does anyway know how I can lookup values in another workbook which are not open? The formula which is causing me problems is as follows:
= SUMIF( 'H:Infozoom[2006-01_assy.xls]New Table1'!$F:$F,$A8,'H:Infozoom[2006-01_assy.xls]New Table1'!$AH:$AH)/60
My macro pulls data from a set of files in a folder and creates an output based on my formatting rules.
Ran into 2 issues though. The first being is after this macro is run it saves a file in the folder with the name "Data Export" and before I had it do this if "Data Export" was already there
Code:
'Check if file name to save exists If Dir$(vFolder & "" & sSubFolder & ".xls", vbNormal) = "" Then
wb.SaveAs vFolder & "" & sSubFolder & ".xls"
MsgBox "Complete!", vbOKOnly
Else
MsgBox "File already exists, could not save!", vbInformation, "COMPLETE!"
End If
What I want it to do instead is change itself and save it as Data Export A, and then also loop for A each time, if A is there go to B , so on and so forth.
-Alternate solution if this is way to challenging, can I have it pop up the Save Message box to let the user try a new name if "Data Export" exists. I was trying to think through that too..
2nd Issue is when I loop the files in the folder I selected in my macro, I want it to ignore "Data Export" files. Before I just took a shortcut and had it save outside of the data folder, which was fine but now we are running on so many files a day that we need it inside the same folder for organization purposes.
That is done with the following
Code:
'Loop through files in folder sFileName = Dir$(vFolder & "")
Do Until sFileName = ""
I was thinking maybe I can add an error handler to the loop? Before Do Until? Something like this? But how I can add it into the loop?
Code:
If sFileName Like "????.?.xls" Then
Basically I want to point my Excel sheet to a bunch of external Excel files. To get data from an specific cell (in this case, cell F10) of the external file, all I have to do is this: ...
View 9 Replies View RelatedHow can I open Book2.xls (in the same folder) in 'read only' mode, using a macro from Book1.xls? Book2 might already be open or it may not. I then need to return control to Book1.
View 13 Replies View RelatedBelow is the macro to work between my TEST.xls file and another worksheet which is opened within the same workbook with the TEST file. If there are more than 2 files, the code ActiveWindow.ActivateNext won't work.
The number of files received from my suppliers varies depending on how busy the volume is. It can be as many as 20 files a day.
ActiveWindow.ActivateNext
Range("C2").Select
ActiveCell.FormulaR1C1 = "=IF(RC[5]
I have a list of numbers and I have corresponding text files which I named by using these numbers as reference
is there a possible macro to delete those rows which have corresponding text files by checking in a specific folder if that file name exists
I have an excel spreadsheet used to populate word documents based on a template file that is loaded like this....
View 9 Replies View RelatedThrough excel I run a dos program which spits out a results file and my macro then opens this file in excel. The only problem is the macro tries to open the file before the other program has writen it. I have tried to fix this using the
View 5 Replies View RelatedHow can I check if a file exists with VBA?
View 3 Replies View RelatedI would like to have a user designed function that will tell me if a file exists in the specified directory.
For example, my file name is wd1.xlsm. I have another udf that tells me my current file path - e.g. C:All Sales People Quotes System.
I combine these two in say, cell D4 and so have C:All Sales People Quotes Systemwd1.xlms
Now I would like a udf that I can put in E4 that will tell me if wd1.xlsm exists in the C:All Sales People Quotes System directory.
a macro to check if a file exists before saving. The code saves the file OK if the filename does not exist but fails if it does.
Sub CheckFileName()
Dim FName As String
FName = ThisWorkbook. Name
'saves file
Dim FPath As String
FPath = ThisWorkbook.Path & ""
Dim y As String
I am using the following VB code to check if a file exists and if so add a formula in my workbook providing data from that file.
I have pre-pulled raw data in the directory "H:BusinessRptTest for scripts" which is named firstly by the day of the month and then what data it is.
- i.e/ 13_CAI_AgentStats.xls
The idea of my code is to check firstly whether the file exists (i.e has the data been pulled yet) and then if so to extract the data I need from the correct sheet and if not to add a zero instead.
I thought all was ok, but if the raw workbook is not open I get a #REF error.
I have looked at some posts for getting info from a closed workbook on this site but I can't get my head around incorporating them into my code!
Code listed below
Sub Check_File_Exists()
For date_test = 1 To 31
If Dir("H:BusinessRptTest for scripts" & date_test & "_CAI_AgentStats.xls") "" Then
Range("AE" & date_test + 11).Formula = "='H:BusinessRptTest for scripts[" & date_test & "_CAI_AgentStats.xls]" & date_test & "_CAI_AgentStats'!$D$4"
Else
I can use a FileDialog to have a file selected. But I still need to check if it really exists before continuing. How to do?
(I know there is a function FileExists but do not know how to use it with FileDialog if this is the way to do it)
Select Case True
Case True
If wbEXT = "C:KPI 0015 external Shortageswk" & CStr(VBAWeekNum(Now(), 1)) >= 0 And _
wbINT = "C:KPI 0044 internal Shortageswk" & CStr(VBAWeekNum(Now(), 1)) >= 0 Then
Case False
varAnswer = MsgBox("KPI Current week No missing", vbOK, "Warning")
If varAnswer = vbOK Then
Exit Sub
End If
End If
End Select
rest of code here
basically if current week files exist carry on , if they dont then pull up a msgbox with ok button to stop sub
Is it possible to search a directory looking for a particular file, then if found, copy the directory and all its contents to another location?
it should be noted that not all of the files will be *.xls.
My raw data is exported in CSV format. Is it possible for Excel to link to the data or can it only link to an Excel format workbook?
View 1 Replies View RelatedI have file name "WM" from where I want to run macro and want that It open a File let say "test" & do the rest of the functions. like if I have following code how can it possible.
"TML" sheet is on file "WM" and "MD" sheet is on file "test".
Code:
Sub Copy_on_backup_file()
Workbooks.Open Filename:="C:UsersBinDesktop est.xls"
'*** Select the destination cell
With Sheets("TML")
LR = .Range("A" & Rows.Count).End(xlUp).Row
Range(.Cells(3, 1), .Cells(LR, 3)).Copy Sheets("MD").Range("B" & Rows.Count).End(xlUp).Offset(1)
End With
[Code]...
I have a userform which saves project details....
Part of the makeup of the userform is a label control (label11) which can store a filepath for an external file (word doc, PDF etc)
How can i open this external file? (the filepath is stored as the caption)
I have been trying something like this before, i could not get it fixed. Let's give it another go:
I have a number of files in a specific folder. I need to extract values from cell Sheet1!G42 out of [b]every file[b] in this folder. Problem that occurs, is that I do not know how many files are in this folder, neighter do I know what the filenames are. I need some magic to perform extraction of the desired values.
As for the files in the specified folder I have this VBA code, that suits my needs just fine:
Private Sub Workbook_Open()
Dim fileList() As String
Dim fName As String
Dim fPath As String
Dim I As Integer
This code will display all found files, including their path in column AD. (as plain text)
[b]Question that remains:[b] how am I to fix a formula In (column AE) that will extract the value found in Sheet1!G42 of each file? This must be very easy, but i can’t get this to work….