How To Close Text File That Was Opened By DLL Called By Excel

Mar 11, 2014

I call it from a macro. It is supposed to write some temporary files, and close them in the end, and delete them. Sometimes, the dll can't close properly, and the text files remain open.

With error treatment in my macro, I can continue execution, but i need to delete that files.

Since the dll DOES NOT CLOSE the files, i'm not able to delete them in my macro.

I need some way to close that files, in order to delete them.

When I use GetFile to reference the file, it remains as "File", which does not accept "Close" method. I can reference the file with myfile.OpenAsTextStream, but this way it seems to me that the file is opened again, and the "Close" method does not work either, with the file defined as a TextStream object.

If I close excel, I'm able to delete those files, but that's not the way I want. Since IT'S OPEN IN EXCEL PROCESS, I imagine there's some way to close it.

View 1 Replies


ADVERTISEMENT

Looping, Open Text File, Copy Text, Close Text File

Sep 18, 2009

I have an existing spreadsheet with a column of strings (actually VIN numbers). These numbers correllate to a bunch of text files, that can exist in one of three folders (UsernameDesktop1, 2, or 3) on my desktop. What I need the macro to do is:

1) get the filename from A2 (A1 is a heading row)
2) Find the appropriate text file in one of the three folders
3) Put the folder name into I2
4) Scan the text file for some strings, and copy some data that follows those strings into J2:O2 (I can handle programming this)
5) Close the text file
6) repeat above for the remainder of filenames (about 1800 files)

View 3 Replies View Related

2nd Excel File Trying To Open When 1st Is Opened

Apr 26, 2012

While opening one Excel file I get an error message saying that a 2nd file could not be opened because it cannot be found. I do not want this 2nd file to open. WHere do I find the "command" that is telling this 2nd file to open.

View 3 Replies View Related

Excel 2010 :: Locking File If Already Opened?

Aug 5, 2013

I am runnig Excel 2010. I was wondering how I lock an Excel file (make it 'Read Only') if someone already has it open?

View 1 Replies View Related

When Use VBA To Open File - Notify User When Excel Opened By Other

Jun 14, 2014

I use the vba to open excel file. like workbooks.open filename:=abc.xlsm but I found that if the file is opened by other. Excel still open the file but it will not notify user that it is opened as read only.

Would you add more line to notify user if the file is opened by other?

View 2 Replies View Related

Excel 2010 :: VBA Error When File Opened From Email?

Aug 30, 2012

I've got a file that works fine on my computer. When I email it to anyone with 2010 and they open it from their email account (Outlook 2010), the file automatically opens up in 'Protected Mode'. If the user selects "Enable Editing" the user receives 'Run Time error 91: Object variable or with block variable not set'.

If the user closes out the vba error and saves the file to their computer and reopens the file, it works fine.

BTW, it is not a complex macro, it is error out at

ActiveWorkbook.Sheets("Worksheet").Select

View 1 Replies View Related

Opened Up Excel 2010 File In 2013 Now It Won't Work Back At Office

Oct 29, 2013

How come in 2013 there does not seem to be an option to "save as" an earlier version of Excel, specifically 2010?

I opened up something from work (2010) at home (2013) and must have refined it (nothing complicated or fancy that 2010 can't do!)

Now it won't open up at work and tells me to reopen and save as the old version.But 2013 won't let me.

View 4 Replies View Related

Close Down Webpage Opened Via Hyperlink?

Jun 19, 2013

I have a list of hyperlinks.

I want to open each one, grab the web address, close page, move onto next link.

I am stuck on the closing part.

This is what I have so far.

Code:
Dim rng As Range
Dim LastRow As Long
Dim cl

[Code]....

View 8 Replies View Related

Automatically Close Workbook If Another Opened

Oct 29, 2006

I have a workbook that automatically saves itself when it is closed without prompting the user. Now I need to make the workbook automatically close if another workbook is opened.

if my_workbook.xls is opened and you open another workbook, I need my_workbook.xls to close instantly.

View 7 Replies View Related

VB Code To Close Workbook Opened After Certain Date

Jan 17, 2013

I have a workbook which should only be used between certain dates

In this example between 3rd March 2013 and the 1st March 2014

Would it be possible that if the user opens the workbook outside of this date range an error message could appear then the workbook would then close ?

View 6 Replies View Related

Close Text File With Code

Dec 29, 2006

I am trying to inch my way forward to writing a macro that will read in an external CSV file into a sheet (my next task will be to spread the date between multiple sheets based on regions). My first attempt at code is the following

Sub read_csv()
Dim strLine As String
Dim i As Integer
Dim filename As String
Dim ans As String
filename = "C:Documents and SettingsMichaelMina dokumentMina datakällorD123905.csv"
Open filename For Input As #1
i = 1
While Not EOF(1) And i < 10
Line Input #1, sLine
ans = MsgBox(sLine, vbOK, "hello there")
i = i + 1
Wend
' Close filename
End Sub

A couple of problems arise. When I debug the code, if I remove the comment on the close filename, the debugger complains with error 13 (incompatible types). If I comment the line and try and run the code twice in a row, I get a complaint about error 55 - file already open. I'm guessing that the close filename is the correct syntax - if it isn't, what should it be??

View 5 Replies View Related

Close Excel File

Nov 10, 2009

I wrote this code to open an excel file when a button is pushed. I also have another piece of code to close the excel field when another button is pushed. The problem: the code to close the excel only works on my computer. There is no error message, but the file doesn't not close on others' computer. Can you please advise on a solution?

View 7 Replies View Related

Save And Close File If There Is Text In Cell Range

Nov 12, 2012

I do have the below code to safe a file and close it:

Sub Save_Close()
'
' Save_Close Macro
'
'
ActiveWorkbook.Save
Application.Quit
End Sub

I would like to do additionally something else. I need a macro to do the above, but it should first check if cells A2:C9 do contain text. The text could be anything.

If there is text in ALL the cells, then the macro should save and close the file. If there is text missing in at least one of the cells, a message box should appear saying 'Please fill out all cells'.

View 3 Replies View Related

Macro To Close One Excel File And Open Another?

Jul 18, 2014

I have created several excel files as I cannot open them all at once since they are too large. So I have to open one excel file whilst closing another.

part1
part2
part3
part4
part5

I want a macro that opens the excel file part 1 and part 2. Then it should close part 1 and after closing part 1 it should open part 3. Once part 3 is open, part 2 should be closed and when part 2 is closed part 4 should open. When part 4 is open, then part 3 should be closed and part 5 should open.

View 1 Replies View Related

Open ANY File Type From Excel, Save And Close

Aug 16, 2008

I need to open about 2000 documents one at a time, and save them with a different name.

they are a mix of word documents, PDFs and .jpg pictures.

some VBA like:


Open.file strPath & nextfile
where strpath = C:Temp

and nextfile = picture01.jpg

What should the line be? or is it more complex than a single line ?

View 9 Replies View Related

Opening File Causes: Excel Has Encountered A Problem And Needs To Close

May 23, 2008

I am trying to open an Excel file that was emailed to me in zipped file that requires macros. When it asks me if I want to enable macros it gives me an error and will not open. Is there a setting I need to change?

View 5 Replies View Related

Automatically Open File In Specific File Path When Another Sheet Is Opened

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

Debug Function Called From Another File

Jun 26, 2007

I have a macro that calls functions from another workbook.

For example:

Private Sub Worksheet_Change(ByVal target As Range)
If ThisWorkbook.OpenCommon <> -1 Then _
Application.Run Workbooks("common.xls").name & "!Arkusz1.CellChange", target
End Sub

But when I get an error in CellChange function from "common.xls" workbook, debugger points only to the third line of the code above, not to the bad line in called function.
Is there any way to change this behaviour (maybe some tool etc.)?

View 5 Replies View Related

Compile Error On Close Of Excel 2003 But Not On Close Of Workbook

Mar 22, 2012

I am using Excel 2003.

It’s been working perfectly up until around an hour ago. However, now when I close Excel, I get compile errors.

These compile errors seem to be because Excel is trying to access controls in the workbook after it has closed. Since the workbook is closed, VBA can no longer ‘see’ the controls, and therefore it thows up errors.

I’m also getting a similar error on a Worksheets("DataExplorer").unprotect line, which seems to be because the worksheet isn’t there after closing.

These errors only occur when I close the whole excel application using the big cross in the top right. If I just close the workbook (using the smaller cross just below the big cross in the top right of excel), it doesn’t throw up these errors.

Just to clarify: all of the code runs perfectly when Excel is open. The errors are being thrown up for lines of code which run without problem until Excel is closed.

View 9 Replies View Related

Log Of Who Has Opened File

Jan 7, 2009

Is there a way to create an outside log of who has opened an excel file and when?
I am looking to add some accountability to a project.

View 3 Replies View Related

Write VBA Code That Will Generate Text File With ALL Changes Made To Excel File

Jun 4, 2012

Is it possible to write vba code that will generate a text file with ALL changes that were made to an excel file. Ex. If Cell A17 = "Monday, June 4, 2012" and a user updates Cell A17 to "N/A", I would like to know what the value was before and after the udpate was made.

View 8 Replies View Related

Import Text File Into File Where Rows Exceed Excel Row Limit

Jun 3, 2009

I have a workbook with many spreadsheet named Sheet1, Sheet2 and so on. Each sheet is filled completely upto 65536 rows. This data is being picked up from a CSV file. In this file there are sites with each site there is a assciated set of data. What happens is the data that extracts data does not differntiate between sites and when it reaches to the end of worksheet it splits the data into next sheet. So I am trying to create a macro to check each spreadsheet starting with the last sheet in the work book for example last sheet in the workbook is seven it should go to sheet6 and if there is a blank row after row 64000 it should cut all the rows and move them to sheet7. Then it should goto sheet5 and do the same and keep on doing it until it reaches sheet1.

View 9 Replies View Related

Excel Called From VBS Does Not Fully Exit

Nov 5, 2009

I am trying to sort a csv file through a VBScript. My problem is that Excel continues to run as a process on script completion. Running multiple variation of this script results in multiple instances of Excel being present in the WinXP Process Manager.

Set xlObj = CreateObject("Excel.Application")
xlObj.Visible = false
xlObj.Workbooks.Open "C:Test.csv"
xlObj.ActiveWorkbook.ActiveSheet.Range("A1").Sort xlObj.ActiveWorkbook.ActiveSheet.Range("A1"),,,,,,,0
xlObj.ActiveWorkBook.Save
xlObj.ActiveWorkBook.Close true
xlObj.quit
set xlObj = Nothing
As a second part to my question, is there any way to modify the code to allow multiple field sorts, i.e., A1 is Primary, C1 is secondary?

View 9 Replies View Related

Use Opened File In Formula?

Aug 18, 2014

Is it possible to insert the filename automatically in formula after the input from the user?

I want to ask the user to input a filename and afterwards, call that filename in an Index-Match

I have the below formula with the sample filename:

ActiveCell.FormulaR1C1 = _
"=INDEX('[filename1.xlsx]DATA'!C9,MATCH(RC[1],'[filename1.xlsx]DATA'!C32,0))"
Range("A2").Select

View 1 Replies View Related

Csv File Different When Opened Manually And Via VBA

Jan 21, 2009

Opening it manually the dates in column C are all consistently date numbers. i.e. using the =ISNUMBER() function to test them, they all return True
However when I include the VBA instruction:

View 7 Replies View Related

Massage Box When File Opened

Jan 6, 2012

I would like to have a message box pop up when a file is opened requiring a user to enter information (Name), that would then put this name into a cell for later use when they are printing.

View 6 Replies View Related

Disable The Vba In A File Being Opened Using Vba

May 20, 2007

I have excel vba code to open .xls files on my server. Files to open are chosen by the user via a UserForm within my app, it shows them all their files in their directory on my server. How can I open their files (.xls) that they select but DISABLE the VBA from being able to run/execute, if they have any attched to the file?

I now have all code in place to open the file no problem, I just need to know how to disable the VBA part from being "turned on" when the file opens.

View 9 Replies View Related

File Crashes When Opened

Jul 14, 2006

I run a macro which runs saves the active file to a different location to ensure that I retain the original like so -

If ActiveWorkbook. Name = "KEY_DATA_CFT77" + ".xls" Then
ActiveWorkbook.SaveAs Filename:= _
"H:HOME imcEXCELKEY_DATA_2006KEY_DATA_2006_01KEY_DATA_CFT77_01.xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
End If .................................

View 9 Replies View Related

Naming Excel File With Name Of Input Text File?

May 20, 2013

I have a macro that takes a text file as input and produces an excel file as output. I want a macro to store the name of the text file in a variable (without its file extension).

View 1 Replies View Related

Excel 2010 :: Is File Of File Type Text

May 16, 2014

Using Excel 2010

As I am looping through files in a folder, I would like to determine if the file is a text file.

The problem is that all extensions are variable in a pattern such as .078, .051, etc.

In this instance, the extensions are numeric, but I'm trying to figure out a way to handle that is all encompassing to include *.txt, *.tsv, *.csv, *.prn, etc......

How can I handle these efficiently?

View 6 Replies View Related







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