I am having a problem trying to compare a file string to see if the save as file string needs to be overwritten. The logic, I believe, is to compare the 'save as string' with the already open 'file string'. Does this make sense? When the Save File dialog comes up, I need to compare the save as filename with the already open filename, and if its the same name, then ask to be overwritten. I'm not sure where to start. I believe the file extension, '.las' for example, will need to be removed, and then a comparison made. Can anyone help? Thanks in advance
Splitting & Comparing 2 Strings
Collapse
X
-
Tags: None
-
When user opens a file via your code and the common dialog, the file name is retrieved for you and thus you should save that into a variable. From there if user alters the file and selects save, the file name will be the same and the file contents overwritten with the new information. However, if user selects save as, as you have pointed out, then once again the common dialog returns you a path/file name and all you need to do is to compare the two...
Code:Dim Ans As Integer If OrigFileName = SaveAsFileName Then Ans = MsgBox("Overwrite file?", vbYesNoCancel,"") If Ans = vbYes Then 'save code here ElseIf Ans = vbNo Then 'reshow saveas dialog here or do a recursive call to whatever function this is ElseIf Ans = vbCancel Then 'do nothing End If Else 'Save Code goes here End If
Good Luck -
-
I keep getting a runtime error '70', access denied. What does this mean? Code is as follows:
Code:Dim Ans As Integer 'check if originalfile matches saveasfilename If tFile = fSave Then Ans = MsgBox(fSave & " already exists. Do you want to overwrite file?", vbquestion+vbYesNoCancel, "Save As") If Ans = vbYes Then 'save code here Kill tFile '<<<this is the problem>>> If LCase(Right(fSave, 4)) = ".las" Then ' 'copy temp file FileCopy "C:\Temp.dat", fSave Else FileCopy "C:\Temp.dat", fSave & ".las" End If Else If Ans = vbNo Then 'reshow saveas dialog here With CommonDialog1 .Filter = "All Files|*.las*|" .InitDir = fSave .DialogTitle = "Save File As" .ShowSave End With fSave = CommonDialog1.FileName Else If Ans = vbCancel Then 'do nothing End If Else 'Save Code goes here FileCopy "C:\Temp.dat", fSave & ".las" End If
Comment
-
Okay, when you first open the file, how do you do it? Open Statement?...
Code:Open SomeFilePathName For Input As #1
Code:Close #1
Good LuckComment
-
I am using the code below to reference the file:
Code:Set fso = CreateObject("Scripting.FileSystemObject") Set objstream = fso.opentextfile(tFile, 1, False, 0)
Is there any specific way to close the file, if using filesystemobjec t? I've tried just "Close" so it would close anything opened, but it didn't work. Thanks again.Comment
-
I had resolved the issue. I just needed to close the fso.objstream:
Code:fso = objstream.Close
Comment
Comment