Range Selection in VBA

46 просмотров
Перейти к первому непрочитанному сообщению

Satendra kumar

не прочитано,
2 сент. 2014 г., 06:39:3502.09.2014
– excelvb...@googlegroups.com, excelvb...@googlegroups.com
Hi All Expert,

Please solve my Range Selection in VBA query. i am facing problem in highlight range.





Private Sub CommandButton1_Click()
Dim fso As FileSystemObject
Dim fl As File
Dim rng As Range
Dim str As String
Dim fldr As Folder
Dim sh As Worksheet
Dim abw As Workbooks


Set fso = New FileSystemObject
Set sh = ThisWorkbook.Worksheets(1)

Set rng = sh.Range("a5:a" & sh.Cells(Rows.Count, "a").End(xlUp).Row)


Set fldr = fso.GetFolder("C:\Users\satendra.kumar\Downloads\New folder1")
            
For Each fl In fldr.Files
    Workbooks.Open filename:=fl
    
            str = Workbooks(fl.Name).Sheets(1).Range("B3").Value
            
            
            ActiveWorkbook.Sheets(1).Range ("a5:a" & Sheets(1).Cells(Rows.Count, "a").End(xlUp).Row)
            
            
            ActiveWorkbook.Sheets(1).Columns.AutoFit
            ActiveWorkbook.SaveAs filename:="C:\Users\satendra.kumar\Downloads\Resdex\" & str & ".xls"
             
            
            
    ActiveWorkbook.Save
    ActiveWorkbook.Close
    
Next fl
End Sub


--
Thanks & Regards
Satendra Kumar

Satendra kumar

не прочитано,
2 сент. 2014 г., 09:41:1302.09.2014
– excelvb...@googlegroups.com, excelvb...@googlegroups.com
Done

Vaibhav Joshi

не прочитано,
2 сент. 2014 г., 09:54:3202.09.2014
– excelvb...@googlegroups.com, excelvb...@googlegroups.com
Hi

1st change line 6 to Dim fldr As Scripting.Folder

also what is use of this line?
            ActiveWorkbook.Sheets(1).Range("a5:a" & Sheets(1).Cells(Rows.Count, "a").End(xlUp).Row)


Line:             ActiveWorkbook.Sheets(1).Columns.AutoFit is perfectly fine!!


Line :             ActiveWorkbook.SaveAs Filename:="C:\Users\satendra.kumar\Downloads\Resdex\" & str & ".xls"
above line will give error only if content of sting str is illegal so  check what is content str


Cheers!!




On Tue, Sep 2, 2014 at 4:09 PM, Satendra kumar <satendr...@gmail.com> wrote:
--
----------------------------------------------------------------------------------------------------------------------
You received this message because you are subscribed to the Google
Groups "Excel VBA Codes & Macros" group.
 
To post to this group, send email to
excelvb...@googlegroups.com
 
To unsubscribe from this group, send email to
excelvbamacro...@googlegroups.com
 
For more options, visit this group at
http://groups.google.com/group/excelvbamacros
---
You received this message because you are subscribed to the Google Groups "Excel VBA Macros" group.
To unsubscribe from this group and stop receiving emails from it, send an email to excelvbamacro...@googlegroups.com.
To post to this group, send email to excelvb...@googlegroups.com.
Visit this group at http://groups.google.com/group/excelvbamacros.
For more options, visit https://groups.google.com/d/optout.

Ответить всем
Отправить сообщение автору
Переслать
0 новых сообщений