Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi all
Have piece of code that opens a csv workbook in hidden mode and then list data out. The csv format has changed and I want to insert a row and delete a column... can this bee done with hidden workbooks/ sheets?? cheers George |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Ggalla1779 formulated the question :
Hi all Have piece of code that opens a csv workbook in hidden mode and then list data out. The csv format has changed and I want to insert a row and delete a column... can this bee done with hidden workbooks/ sheets?? cheers George Yes! Just use a fully qualified ref to the sheet in the hidden workbook. Of course, you'll need to know where to insert the row and which column to delete. Example... Sub EditHiddenWkb() Dim wks As Worksheet Set wks = Workbooks("Book1").Sheets(1) With wks .Rows(2).Insert shift:=xlDown: .Columns(2).Delete End With End Sub ...where Workbooks("Book1") is hidden and Sheets(1) contains data. A new row is inserted AT row 2, moving row 2's data into row 3 position and so on down the sheet. Columns("B") is deleted, moving column "C" into column B's position and so on across the sheet. -- Garry Free usenet access at http://www.eternal-september.org ClassicVB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
On Monday, 25 June 2012 02:48:18 UTC+1, GS wrote:
Ggalla1779 formulated the question : Hi all Have piece of code that opens a csv workbook in hidden mode and then list data out. The csv format has changed and I want to insert a row and delete a column... can this bee done with hidden workbooks/ sheets?? cheers George Yes! Just use a fully qualified ref to the sheet in the hidden workbook. Of course, you'll need to know where to insert the row and which column to delete. Example... Sub EditHiddenWkb() Dim wks As Worksheet Set wks = Workbooks("Book1").Sheets(1) With wks .Rows(2).Insert shift:=xlDown: .Columns(2).Delete End With End Sub ..where Workbooks("Book1") is hidden and Sheets(1) contains data. A new row is inserted AT row 2, moving row 2's data into row 3 position and so on down the sheet. Columns("B") is deleted, moving column "C" into column B's position and so on across the sheet. -- Garry Free usenet access at http://www.eternal-september.org ClassicVB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion Thanks Gary Is there a way to make it visible or save changes....so I can check if I have changed the csv file correctly? cheers George |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Ggalla1779 wrote on 6/25/2012 :
Sub EditHiddenWkb() Dim wks As Worksheet, wkb As Workbook Dim vAns As Variant, sMsg As String Set wkb = Workbooks("my.csv"): Set wks = wkb.Sheets(1) With wkb 'Get the position to insert a new row, 'and the label of the column to delete. sMsg = "Enter the row number position to insert the new row AND " _ & "the label of the column to delete, separated by a comma." _ & vbCrLf & vbCrLf & "Example: 2,B " vAns = InputBox(sMsg) If vAns = False Then Exit Sub '//user cancels 'Insert row and delete column vAns = Split(vAns, ",") With wks .Rows(vAns(0)).Insert shift:=xlDown: .Columns(vAns(1)).Delete End With 'wks 'Confirm success .Visible = True sMsg = "Do you want to save the changes to " & wkb.Name & " ?" vAns = MsgBox(sMsg, vbYesNo) .Visible = False: If vAns = vbYes Then .Save Else .Saved = True End With 'wkb End Sub -- Garry Free usenet access at http://www.eternal-september.org ClassicVB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() I tried that bu didnt work, changed it a bit Set xlAppx = New Excel.Application Set wkb = xlAppx.Workbooks.Open(Filename:=MyFile) Set wks = wkb.Sheets(1) wkb.Visible = True Doesnt like this says its .Visible isnt available..this will be excel 2003 |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Ggalla1779 explained on 6/26/2012 :
I tried that bu didnt work, changed it a bit Set xlAppx = New Excel.Application Why are you starting a new instance of Excel? I thought the hidden workbook was in the running instance! Set wkb = xlAppx.Workbooks.Open(Filename:=MyFile) Set wks = wkb.Sheets(1) wkb.Visible = True Doesnt like this says its .Visible isnt available..this will be excel 2003 Well, I tested the code in XL2003 and it worked for me. The code assumes the hidden workbook is in the same instance of Excel that the code is running in. -- Garry Free usenet access at http://www.eternal-september.org ClassicVB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Am modifying code thats there they open new instance for hidden workbook so user doesnt see it |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Ggalla1779 formulated the question :
Am modifying code thats there they open new instance for hidden workbook so user doesnt see it That's not necessary because you can open it in the same instance and hide the workbook there. In either case, the code I posted worked for me using the same instance. The approach you're using is a bit more complex but should still work as long as you have a fully qualified ref to the instance and the workbook/worksheet you're working on. Alternatively, you could use standard VB[A] procedures for file I/O to read the CSV into memory and work on it there (or 'dump' it into a hidden temp worksheet). When you want to view the data just 'unhide' the temp worksheet. When satisfied the data is correct just 'dump' it back into a CSV and delete the temp worksheet. This will be orders of magnitude faster and no memory spaces to cleanup. (Every object you create must have space reserved for it in memory. This needs to be released as you're done with each object) -- Garry Free usenet access at http://www.eternal-september.org ClassicVB Users Regroup! comp.lang.basic.visual.misc microsoft.public.vb.general.discussion |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Garry thanks for reply
The reason they used a new workbook is the main spreadsheet is protected and unlocked as they need it Opening a new workbook was the workaround for it....they do it alot tbh and I think its really wasteful... I got it working by making ref to sheet opened and then copying the hidden sheet, then setting the ref to that. I felt a pang as I copied sheet !! so now its kinda getting there but had to put in the sheet ref here and there so there rest of code would work |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Workbook has [Group] at the end of teh file name when opened | Excel Programming | |||
Workbook has [Group] at the end of teh file name when opened | New Users to Excel | |||
Keeping a workbook hidden when opened via VBA??? | Excel Programming | |||
Keeping a workbook hidden when opened via VBA??? | Excel Programming | |||
Is Workbook read-only because of file permission or because file is already opened? | Excel Programming |