Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2970|回复: 0

VBA 一个按钮导入文件,另一个按钮对这个文件进行编辑

[复制链接]
发表于 2014-8-1 01:25 | 显示全部楼层 |阅读模式
我想实现用一个按钮控件导入任意一个文本文件,用另一个按钮对打开的该文件进行编辑,代码应该怎么写,导入的部分和编辑部分的代码已经完成了,就是不知道如何关联??求帮助~~
导入的部分是这么写的:
Private Sub Selected_File_Click()
Application.ScreenUpdating = False
Application.Dialogs(xlDialogOpen).Show
ActiveWindow.Visible = False
Application.ScreenUpdating = True
End Sub
这是编辑的部分:
Private Sub Conversion_Click()
Call EE
End Sub
Sub EE()   
    Rows("1:4").Select
    Selection.Delete Shift:=xlUp
    Range("A2:A300").Select
    Selection.TextToColumns Destination:=Range("A2"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
        Semicolon:=False, Comma:=False, Space:=True, Other:=False, FieldInfo _
        :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1)), TrailingMinusNumbers:= _
        True
    Columns("A:D").Select
    With Selection
        .HorizontalAlignment = xlLeft
        .VerticalAlignment = xlCenter
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Columns("A:A").Select
    Selection.Delete Shift:=xlToLeft
    Columns("C:C").Select
    Selection.Cut
    Columns("B:B").Select
    Selection.Insert Shift:=xlToRight
    Rows("1:1").Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    ActiveWorkbook.SaveAs filename:="C:\Users\asus-pc\Desktop\" & filename.Text & ".rec", _
        FileFormat:=xlTextPrinter, CreateBackup:=False
    ActiveWorkbook.Close Savechanges:=True
    Application.Quit

End Sub


您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2025-8-16 03:14 , Processed in 0.149756 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表