I have a spreadsheet with a macro that saves a backup s/s to a particular folder, but the problem I have need the macro to check the filepath is that of the original s/s before running.
Its so that when people take copies of the main s/s and save them to their desktop I dont want the copies being saved in the backup folder
macro is below
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If ActiveWorkbook.ReadOnly Then Exit Sub
If MsgBox("Do You Want To Save A Backup?", vbYesNo) = vbNo Then Exit Sub
Dim fso As Object
Dim objFiles As Object
Dim myWkBk As String
Dim myFName As String
Dim BkUpDir As String
Dim CountFiles As Integer
Dim mydate As Double
I am using below mentioned Code for checking if certain file exist on Path. Its working on my home PC (XP SP2 Excel 2003). BUT its not working on my office PC (XP SP2 Excel 2003).
Can somebody tell me why its not working in my office PC ( or if its missing something, then from where can i download it.)
Sub CheckFiles() Const strFolder = "C:Documents and SettingskreshnrDesktopTest" Dim fso, msg, i Dim rngData As Range
Set fso = CreateObject("Scripting.FileSystemObject") Set rngData = Sheets("Sheet1").Range("A1")
With rngData Do While .Offset(i, 0).Value "" If (fso.FileExists(strFolder & .Offset(i, 0).Value & ". ")) Then .Offset(i, 2).Value = "Yes" Else .Offset(i, 2).Value = "No" End If i = i + 1 Loop End With End Sub
I have an application that requires users to download a file from a location that is then imported at their execution into the application. I've done my best to counsel users to download the file to their desktop (for ease of locating) and to stick with a standard filename so that there are no errors. Some of these people just don't take direction well, will save the file wherever, or save the name inappropratly, or worse, open up multiple copies of the same file corrupting the name: ie: FileName.xls, FileName.xls(1), FileName1.
I have some code traversing a directory of folders and subfolders on a shared server and returning a list of those file paths. Around 6000 folders with about 2 subfolders on average. This returns a list of 12000 filepaths but takes around 13-15 minutes to do. Each path looks something like this:
I need to check cell G5 (which is G4-G3) before running a macro. if G5 is zero i need to pop up a message to inform the user to enter data in cells G3 & G4. And if G5 is greater than Zero the macro shud run.
I have some code here that I am using to find matches in Column D and then remove colored cell once the match is found. I am in putting the data line by line from a Barcode scanner and only want to run the macro if the date in Column A is today. Here is the code I am using.
How can I run a DOS .bat (batch) file from within a Macro? This is what I came up with so far and it seems to work. The only thing is that I need this to have relative paths, running from the same directory the Excel Workbook is in.
hi, i need a macro that will open the below file path, and when i select the file i would like the macro to copy the active sheet from the source file being opened from range A2:L10000 and then paste special values to destination CELL A16 of the activesheet of the workbook.
I would like the date format for the below to be generic so it will apply for all months and years.
I have a macro in excel that saves to an external text file, but the excel workbook (and the text file) will be copied to different folders so i need it to alway read the file from the location the worksheet was opened from. I hope that makes sense
Ive tried using ActiveWorkBook.path but that doesnt work, maybe im just using it the wrong way
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?
I have code to create a new workbook, and when I try to rename it I get "Compile error: Can't assign to read-only property."
Dim objXlApp As Object Dim wkb As Workbook Dim wks As Worksheet Set objXlApp = CreateObject("Excel.Application") ' Create a workbook Set wkb = objXlApp.Workbooks.Add ' Delete all worksheets bar the first one. For Each wks In wkb.Worksheets If Not wks.Index = 1 Then wks.Delete
End If Next wks 'Create some worksheets and names With wkb .Worksheets(1).Name = "myWorksheet1" .Worksheets.Add.Name = "myWorksheet2" .Worksheets.Add.Name = "myWorksheet3" .Worksheets.Add.Name = "myWorksheet4" End With...................................
I have got a master workbook and I have written macro to copy and paste data on another workbook. write a macro to save the new workbook to a file path with a file name where both file name and path are stored in master workbook sheet...
I have a report send to me daily. And I want to have a macro to save this report in the daily folder, such as “c:
eports8052008”, so tomorrow 's folder would be “c:eports8062008”.
All the daily folders already exist. Just need to change the file path. I tried some codes including sPath and format(now(), “mmddyyyy”), get error message.
I have a form in Access with a button that opens an Excel file. I think I've seen vba code to tell if a specific Excel file is open already. What I'm looking for is a way to tell if an Excel file is already open when you don't know the filename of the Excel file. Is that possible? Or at the very least is there a way to be able to tell if Excel is already open?
The other day, I had posted a macro, which copies one of the sheets from a workbook, on to a blank sheet, and then saves it with a name obtained from the value of cell E7. I required certain modifications to it, before I could implement it.
You will find it here and the code looks like this:
I know how to check for a path exsistance. If Dir(DEST, vbDirectory) = "" Then MsgBox "Path does not exist" (while DEST = "C:TempMike"). I would like to add a question which will determine if the user wants the Macro to create that Path.
1. I do not know how to create that path via VBA Code. 2. What if 'C:Temp' allready exists and only 'Mike' has to be added/created !?
How to save a file, with file- name. but the directory is to be read in worksheet "towns" in Cell1 (brussels) and filename in worksheet "names" in cell B2 (i.e. winter), so it saves to c:russelswinter.txt as a wordpad or kladblok txt file, that keeps a number, so each time we push a button "go back from worksheet names to worksheet towns" the "number" that is saved in the txt document goes up by value +1. In Flemisch, the "old" code goes as follows, and saves the number in the txt file Factuurnummer7.txt. But I want that the file name (here: FactuurNummer7) can be a variable text issue, which has to be read - as already noticed - in cell B2 (with the word WINTER). So the are 2 worksheets: towns, ans names
pad$ = Application.DefaultFilePath 'controle = Dir(pad$ + "FactuurNummer7.txt") 'If controle = "" Then GoTo EerstAanmaken 'Open pad$ + "Factuurnummer7.txt" For Input As #10 'Input #10, Nummer1 'Close #10......................
Below is the current code I have for File Copy before the workbook closes. This file will be distributed all over and obviously will not have the same old path and new path locations as I have in my code also will not have the same file name. Is there anyway to still perform the file copy without knowing the old path and file name and possibly have message box pop up to ask the copy to location and use that in the new path string?
Sub Macro1() Dim fs As Object Dim oldPath As String, newPath As String oldPath = "I:EXLDATAMC Daily" '<---Where the file is currently located newPath = "H:South RegionOrlando Mail Services2008DI" 'Since the super shared drive is super slow we will just copy and replace this file each time before we close and of course after we save Set fs = CreateObject("Scripting.FileSystemObject") fs.CopyFile oldPath & "" & "OrlandoMail.xls", newPath & "" & "OrlandoMail.xls" Set fs = Nothing End Sub
I just found a code to copy file path and file contents. However it is copying folder path and folder contents.here is my requirement.I will specify a path, macro has to copy that file name in a particular cell, then it has to copy all its contents. ex:
file name 1 has 3 sub files in it, file name 2 has 2 sub files in it--
I am trying to establish if Outlook 2000 is currently running in VBA , I have tried the following code but this only works when the user is actually positioned in "Inbox - Microsoft Outlook" etc. At this point I don't really care where/what the user has open in Outlook but merely to check if outlook is running.
I have tried below but does not work robustly enough. I have also tried AppActivate("Microsoft Outlook") I have also tried IsRunning("Outlook.Application") which does not even compile.
Dim OutlookErr, OutlookBox On Error GoTo OutlookIsNotRunning AppActivate ("outlook") GoTo now_send_email
OutlookIsNotRunning:
OutlookErr = "Outlook is either not open or busy with another task." & vbCrLf & vbCrLf OutlookErr = OutlookErr & "Please Open Outlook, Close any draft emails," & vbCrLf & vbCrLf OutlookErr = OutlookErr & "the Global Address List or other activities and try again." OutlookBox = MsgBox(OutlookErr, vbCritical, "Unable to access Outlook to send email") Exit Sub